I\'m executing a script connecting via password-less SSH on a remote host. I want to set a timeout, so that if the remote host is taking an infinite time to run, I want to c
If all else fails (including not having the timeout
command) the concept in this shell script will work:
#!/bin/bash
set -u
ssh $1 "sleep 10 ; uptime" > /tmp/outputfile 2>&1 & PIDssh=$!
Count=0
while test $Count -lt 5 && ps -p $PIDssh > /dev/null
do
echo -n .
sleep 1
Count=$((Count+1))
done
echo ""
if ps -p $PIDssh > /dev/null
then
echo "ssh still running, killing it"
kill -HUP $PIDssh
else
echo "Exited"
fi