If I use
timeout 10 ssh -n -o BatchMode=yes 1.1.1.1 'sleep 20' > 1.1.1.1.txt 2>&1 &
To give out a remote command on a server, and I kill the SSH connection after 10 seconds, then I can see that the sleep 20
is still running on the server, but there is no SSH connection.
How can I kill the remote command after a timeout, say 10 seconds?
The remote machine is AIX 6.1 (or SLES) and no package is available for "timeout". My client is Ubuntu 10.03.
Best Answer
Assuming your remote server has a POSIX-compliant shell, the following should work:
Indeed the POSIX standard states about
$!
:If the remote system has job control, you can shorten it this way: