westwood01
Technical User
When I run the below script from the cmd line it works as expected. The script will accurately detect whether an ssh connection is available. But, when I put this same script in cron it fails every time, even when an ssh connection is available. Any ideas? Or possibly a better method to monitor ssh connectivity? Thanks guys.
#!/bin/ksh
#set -x
ssh somehost 2>/dev/null &
sleep 5
kill $!
if [ $? -eq 0 ];then
echo $? > /export/home/oper/host.exit
echo successful >> /export/home/oper/host.exit
else
echo $? > /export/home/oper/host.exit
echo failed >> /export/home/oper/host.exit
cat /export/home/oper/host.exit|mailx -r me@mywork.com -s "somehost failed ssh connection" me@mywork.com
fi
#!/bin/ksh
#set -x
ssh somehost 2>/dev/null &
sleep 5
kill $!
if [ $? -eq 0 ];then
echo $? > /export/home/oper/host.exit
echo successful >> /export/home/oper/host.exit
else
echo $? > /export/home/oper/host.exit
echo failed >> /export/home/oper/host.exit
cat /export/home/oper/host.exit|mailx -r me@mywork.com -s "somehost failed ssh connection" me@mywork.com
fi