How to terminate Bash Script if remote session disconnects
Dear All,
i am using a bash interactive script that waits for user input. i have to use this script from ssh session via remote access. if session drops, script stays stuck and BASH chews up CPU utilization:confused :. Can any one guide me how a script can self terminate if remote session is dropped? |
Try these (you'll have to adapt them a bit)
http://redflo.de/tiki-index.php?page...meout+function http://www.ultranetsolutions.com/BAS...r-timeout.html |
Dear chrism01, thanx for your prompt response. i have tested those scripts, but i am not getting result. When i use my script via ssh, it wait for READ action for input data and if ssh is terminated then it stays stuck. I want to make my script susid if there is no input in READ for say 30 seconds
|
Hi
You can use -t for timeout with the read. For example echo "You have 30 seconds to write something:" read -t 30 testvar if [ "$?" -eq "0" ] ; then echo "Oki" else echo "Timed out" fi |
You can return to the script's session by running it through 'screen'. If youf connection drops the script and shell is maintained for you to re-attach once you ssh back in.
'man screen' |
All times are GMT -5. The time now is 09:57 AM. |