I have a program like this:
ssh -q harigm@8.19.71.238 exit
echo \"output value -->$?\"
In the above code, I am trying to SSH to the remote
You could wrap the call to ssh
using the timeout
command. The timeout
command exits with code 124 if a timeout occurs.
timeout 10s ssh -q harigm@8.19.71.238 exit
if [ $? -eq 124 ]; then
echo "Timeout out"
fi
Or, as Vorsprung has commented on your question (as I was looking up the man page!):
ssh -oPasswordAuthentication=no -q harigm@8.19.71.238 exit
which will disallow interactive password authentication. You'd then have to check the exit code.