How to terminate Bash Script if remote session disconnects
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)
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
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 "Timed out"
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.
|All times are GMT -5. The time now is 07:26 PM.|