Cannot do SSH from Cron

Hi,

I am trying to execute a perl script which opens a few SSH session with another host. When this script is executed in a normal enviornment, it wroks fine. All the ssh session are terminated properly, but when the same script is scheduled in the user's cron environment, it results in the SSH session being left opened in an hanged state. It does not seem to do anything.

Can anyone shed some light on this peculiar behavior. I tried making the enviornment in the crontab the same as the one that exists in users .profile ....

Thanks

Nitin

[574 byte] By [Nitin_Nair] at [2007-11-26 8:45:46]
# 1
Hmm, try and add the "-n" flag to ssh.. 7/M.
mAbrante at 2007-7-6 22:30:17 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...
# 2
Tried doing that..doesnt help...
Nitin_Nair at 2007-7-6 22:30:17 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...
# 3

This could be because crond is not associated with any tty.

You should try using one of the Net::SSH2 perl modules instead of "exec"ing your system's SSH binary from within crontab (though I'm not sure whether SSH can work at all without using a tty).

Also another thought is if your ssh script returns output to stdout or stderr, redirect that to /dev/null and then see what the result is.

eg:

20 * * * * [ -x /usr/bin/myssh.pl] && /usr/bin/myssh.pl > /dev/null 2>&1

implicate_order at 2007-7-6 22:30:17 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...
# 4
Also, you could try using a wrapper shell script that calls your perl script and see whether that works.
implicate_order at 2007-7-6 22:30:17 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...
# 5

After lot of research, I could narrow down the problem to the writing to the std out by few commands using ssh..

For example, if I do ls -b on a directory which contains no file, nothing is written on to the std out and this caused the ssh invoked through Cron to hang..If at the same time I use 'ls - a' (which always return atleast . and ..), the SSH command worked fine through the Cron...

So if you ever find the SSH from cron hanging, use alternative commands which write something on the stdout (or write some dummy shell script which after invoking the command will write something onto the standard out)

Nitin_Nair at 2007-7-6 22:30:17 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...