![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| never ending loop | ragha81 | Shell Programming and Scripting | 21 | 10-06-2006 03:07 PM |
| executables ending with * | binums | High Level Programming | 2 | 01-25-2006 08:39 PM |
| File- Ending | spikylina | UNIX for Dummies Questions & Answers | 3 | 03-08-2005 01:00 AM |
| ssh not ending (sometimes) from inside a script, why? | stilllooking | Shell Programming and Scripting | 1 | 09-16-2004 04:42 AM |
| Ending Mail | Peterh | UNIX for Dummies Questions & Answers | 2 | 05-11-2001 12:26 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Ending script after a specified time.
Hi All,
I am having a script, which run fine. But what I want to do is that the script should run for specified time and terminate then ( say for a minute). Can somebody help me for this. I would be greatful. Thanks, Aru |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
If i understand your requirements correctly, you can start the script in background and then sleep for a minute, then stop it.
|
|
#3
|
||||
|
||||
|
I guess you could put this in the start of your script...
Code:
echo "kill $$" | at now + 1 min Code:
End=$((SECONDS+60)) while [[ $SECONDS -lt $End ]] do : do something done |
|
#4
|
|||
|
|||
|
Hi,
Thanks for answering. Please confirm me that whatever I am writing below is what you asked me to do. In my script I want "top" to terminate after 1 min. As I am considerabely new to Unix. I have just written, what I am writing below in file x.sh. Now when I run x.sh ....... it does not terminate after 1 minute. Please help me in modifying the below script. >>>>>>>>>>>>>>>>>>>>>>> End=$((SECONDS+60)) while [[ $SECONDS -lt $End ]] do top >> top.out done <<<<<<<<<<<<<<<<<<<<<<<<<<<< Thanks, Aru |
|
#5
|
|||
|
|||
|
if the checking is to be done inside the script itself,
as of, the n seconds will not be guaranteed for the script to execute where m seconds ( m < n ) would be taken for checking and other calculations, rather, have a wrapper script, pid=call the process to be executed through the wrapper do the checking (for certain amt of time in the wrapper script ) done then pass the kill signal to process kill <val> <pid> |
|
#6
|
||||
|
||||
|
You never said that this was for the top command. Take a look at the manual pages for your version of top. You will be able to specify a delay and the number of iterations to run, e.g....
Code:
top -b -d 5 -n 12 |
|
#7
|
||||
|
||||
|
well in the above while loop i didnt see the SECONDS initiliased to 0, assuming it may not be required, there is no increment of the SECONDS in the while loop, so your while loop will surely not terminate
so in the while loop you may want to add a line (( SECONDS = $SECONDS + 1 )) i hope SECONDS is just a variable and no special shell built-in. Hence it has to be treated just like any other variable. besides, you want SECONDS to really act as a SECOND, so in the while loop, put a sleep 1
__________________
War doesnt determine who is right, it determines who is left |
||||
| Google The UNIX and Linux Forums |