We sometimes execute a script because some of the programs in the script are suspended and timed out, which affects our judgment of the next step. Random we have to set the timeout for functions and processes so that he does not respond after a period of time, return a status.
In the command parameters Ssh-o serveraliveinterval=60 This way can be controlled to 60 seconds.
such as clientaliveinterval=15,clientalivecountmax=3, it will be sent in 15 seconds, 30 seconds sent once, 45 seconds sent once, if three failed to recover the link
But this parameter is not very good, we can add a sleep 100 after the try.
#!/bin/sh
Timeout ()
{
waitfor=3
command=$*
$command &
commandpid=$!
(Sleep $waitfor; kill-9 $commandpid >/dev/null 2>&1) &
watchdog=$!
sleeppid= $PPID wait
$commandpid >/dev/null 2>&1
kill $sleeppid >/dev/null 2>&1
}< C13/>test123 ()
{
ifconfig sleep
ifconfig
# Curl htpp://www.facebook.com
}
Timeout test123
Basic control to about 3s