LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-14-2009, 11:42 PM   #1
zia.hassan
LQ Newbie
 
Registered: Jun 2009
Posts: 2

Rep: Reputation: 0
Question 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?
 
Old 06-14-2009, 11:51 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,342

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
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
 
Old 06-15-2009, 03:45 AM   #3
zia.hassan
LQ Newbie
 
Registered: Jun 2009
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
Old 06-15-2009, 03:55 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,449

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
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
 
Old 06-15-2009, 04:04 AM   #5
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
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'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh session within a bash script Tamaros Programming 1 05-11-2008 03:38 AM
bash - start remote script from local script? babag Programming 7 04-06-2008 05:46 PM
terminate session after 15 minutes jonfa Linux - Security 1 06-22-2007 11:25 AM
how to have bash script check whether it's a x session? bkeeper Linux - Newbie 9 02-21-2006 06:31 AM
Terminate Session Remotely wwnexc Linux - Software 13 01-06-2006 06:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration