![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bash: Exiting while true loop when terminal is not the focus window | acclaypool | Shell Programming and Scripting | 2 | 02-25-2008 06:02 PM |
| why isn't the exit status true? | mjays | Shell Programming and Scripting | 5 | 04-04-2007 09:18 AM |
| Method to exit a for loop | Rohini Vijay | Shell Programming and Scripting | 2 | 11-01-2006 05:56 AM |
| while loop exit | Terrible | Shell Programming and Scripting | 3 | 07-28-2006 05:20 PM |
| csh exit while loop on keystroke | seg | Shell Programming and Scripting | 7 | 12-29-2004 11:45 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
how to exit a while true loop
Hi guys,
I'm new to unix but loving it!! BUT this is driving me nuts as i can't work out the best way to do it. I have a while true loop that i use to monitor something. For my own reasons in ths script i have disabled the CTRL C using the trap command. But i want to put in a option to exit the script using the exit command. So i get it to display the info for say 30 seconds then it loops, then displays the new info. While it is waiting for 30 seconds i want the option to exit the script by pressing say the x key. As im new to unix not sure how to do this, i either work in ksh or bash. Pleeease give me an idea how to do this. ![]() |
|
||||
|
Been told that im not allowed to use the CTRL C to exit the scripts, so i removed the option. (Don't ask me why but the admin was suggesting it caused issues) I want to press any key while the loop is running to exit. So the script is running the loop but also looking for a key press to exit, tried exiting the script using CTRL \ didnt work. IF SIGQUIT is an answer how can i use it in the way i want?
|
|
||||
|
#you can use break to quit the loop.
#you can quit the script itself by using exit once you reach the condition to quit the whole!! If you want to run it for particular time in seconds... here we go #!/bin/sh secs=$1 start=`date +%s` end=$((start+$secs)) while : ; do if [ `date +%s`-eq $end ]; then break fi . . . here goes your monitoring logic done #here you can write the rest of the script or simply put exit 0 ---------now you can run the script passing the arguement as no. of secs you want ti to run!! -ilan Last edited by ilan; 08-25-2007 at 09:52 AM.. |
|
||||
|
Thanks guy for the advice i ended up using.....
answer="No";read -p "Do you want to exit? Answer y to exit. " -t 30 answer;echo " Your answer is $answer"; if [ "$answer" = "y" ];then echo "you have chosen to exit." break else echo "" giving them a 30 second window to exit the script or the while true just continues.. works a treat. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|