Discussion:
Running ssh cmd on cron -- debug2: channel 0: read failed
Joe Park
2006-01-04 21:55:04 UTC
Permalink
Hello,

I've been trying to run some commands on remote machine over ssh as a
cron job. It works fine if I manually run it on command line but it
does not run right if I run it as a cron job. I get 0 exit status which
is strange. I found "debug2: channel 0: read failed" message when I ran
it with -vvv options. I tried both ssh1 with rsa1 key and ssh2 with rsa
key.

Here are 2 output from the ssh.

#### FAILED #### ( Ran as a cron job)
...
...
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Entering interactive session.
debug2: callback start
debug2: client_session2_setup: id 0
debug1: Sending command: rm -v /home/test/testfile.txt
debug2: channel 0: request exec confirm 0
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 131072
debug2: channel 0: read<=0 rfd 4 len 0
debug2: channel 0: read failed
debug2: channel 0: close_read
debug2: channel 0: input open -> drain
debug2: channel 0: ibuf empty
debug2: channel 0: send eof
debug2: channel 0: input drain -> closed
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug2: channel 0: rcvd close
debug3: channel 0: will not send data after close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cfd -1)

debug3: channel 0: close_fds r -1 w -1 e 6 c -1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
debug3: fd 2 is not O_NONBLOCK
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.2 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0


#### SUCCESSFUL #### (Ran from command line)
...
...
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Entering interactive session.
debug2: callback start
debug2: client_session2_setup: id 0
debug1: Sending command: rm -v /home/test/testfile.txt
debug2: channel 0: request exec confirm 0
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 131072
removing /home/test/testfile.txt
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug2: channel 0: rcvd close
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
debug3: channel 0: will not send data after close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cfd -1)

debug3: channel 0: close_fds r -1 w -1 e 6 c -1
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.3 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0


And following is from crontab.

0,30,50 * * * * /usr/bin/ssh -vvv -2 -i
"/home/testuser/.ssh/rsync_key_rsa" ***@192.168.0.101 "rm -v
/home/test/testfile.txt"

Any suggestions on why this is not working?

TIA,

Joe
Darren Tucker
2006-01-11 10:42:12 UTC
Permalink
Post by Joe Park
I've been trying to run some commands on remote machine over ssh as a
cron job. It works fine if I manually run it on command line but it
does not run right if I run it as a cron job. I get 0 exit status which
is strange. I found "debug2: channel 0: read failed" message when I ran
it with -vvv options. [...]
You don't happen to have 2 copies of ssh installed in separate paths,
do you? cron's environment is usually a lot more limited that an
interactive shell's so you might be running different ssh binaries...

If it's not that then I'm not sure what's going on but I have a couple
of things you might like to try: run the ssh command in a nohup and
see if it makes a difference, and try redirecting stdin, stdout to/from
/dev/null on both the client and server (separately).

The other thing: try using adding "-t" to the ssh command line to
allocate a pty on the server side (it's a long shot and not a real
solution, though).
--
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69
Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.
Loading...