How to make a script run for a maximum of "x" number of hours only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make a script run for a maximum of "x" number of hours only
# 1  
Old 05-04-2007
Bug How to make a script run for a maximum of "x" number of hours only

How to make a script run for a maximum of "x" number of hours only
# 2  
Old 05-04-2007
Quote:
Originally Posted by ScriptDummy
How to make a script run for a maximum of "x" number of hours only
What do you want actually.

1. Run a script for specific time stamps ( you can do through crontab)
2. Run a script which executes hourly basis ( implement with "for" and Sleep)

Can you evaluate your requirement pls..?
# 3  
Old 05-04-2007
Hi,

Basically I want the script to run not more than 5hrs. This script actually downloads files from a server. So I want to have a timecheck so that its not more than 5hrs the script is running
# 4  
Old 05-04-2007
I am using the following function in one of my scripts:
Code:
sleep_wake_kill() {
        sleep 21600
        kill $(ptree $$ | awk '{if(NR>1) print $1 }')
}

I call this at the beginning of my code and put it in the background. The function will sleep for six hours, then wake up and kill everything that has anything to do with this process (including the login session).

Call it like this:
Code:
#!/usr/bin/ksh
### assuming that sleep_wake_kill function is already defined
sleep_wake_kill &
# rest of the code follows
...

-Edit
If anyone has another idea, I would love to hear it. I don't know if what I am doing is the best way to handle this.
# 5  
Old 05-04-2007
I guess you could try...
Code:
run_script.sh &
echo "kill $!" | at now + 5 hours

...assuming that you don't cycle through all available process numbers every few hours.
# 6  
Old 05-04-2007
It is probably safer to create a run file with the pid at the script's beginning and then remove it at the end. Then impliment a for loop as stated before, but instead of killing everything with the specified PID you could check for the run file and if that exists then kill the pid specified in that file.
# 7  
Old 05-17-2007
Thanks All

if you could give some examples it would be great
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

3. Shell Programming and Scripting

"Cannot allocate memory" error when run from script

hi in my application there is a line with open(/dev/mydevice,0); it work good when it run manually, but when try to run it within script /////////////////////////////////////////// #!/bin/sh ./device_test 0 0 0 1 1 1 0 0 1 ///////////////////////////////////////// I receive 'Failed... (3 Replies)
Discussion started by: majeed
3 Replies

4. Shell Programming and Scripting

Make scipt except from "Y","y" and "yes" to take [Enter] as being "yes"

This is the script: #!/bin/sh if ; then rm -rf /usr/share/WallpaperChanger; fi if ; then rm -rf /usr/bin/wallch; fi; if ; then rm -rf /usr/share/applications/wallch.desktop; fi if ; then rm -rf /usr/share/doc/wallch; fi if ; then rm -rf /usr/share/man/man1/wallch.1.gz; fi echo "Delete... (4 Replies)
Discussion started by: hakermania
4 Replies

5. Shell Programming and Scripting

Startup Script "run process with Timer"

Hi I have a script that execute every X minute for checking new files in a folder and converting to pdf. Is there any way to start this script automatically on linux startup?. I use sleep function in script with infinite loop. while do killall -u `whoami` -q soffice soffice... (0 Replies)
Discussion started by: zawmn83
0 Replies

6. Shell Programming and Scripting

catalina.sh : need combination from "start" and "run"

heya, can someone help me with following problem. i am not sure how far you know the catalina.sh script from tomcat. when i start my tomcat with "catalina.sh run" then the startup-process-output will be printed out on the console, but the tomcat process is started in current shell/session, so... (1 Reply)
Discussion started by: Filly
1 Replies

7. UNIX for Dummies Questions & Answers

Maximum input file size in "Diff" Command

Hello, Can anyone let me know what is the maximum file size that can be given as input for the "Diff" Command in Unix? I have a file size as large as 28MB and which can also increase. Will I face any issues with such a file size. If yes, What is the other alternative. Thanks in advance for... (1 Reply)
Discussion started by: Neeraja
1 Replies

8. Programming

how could i make a program mixed with many "|", "<" and ">"

I have written following code to do: ls -l | wc -w, it works: but when there are not only a single "|", if there are more such as: ls -l | sort -r | sort | sort -r, This program does not work, i want to know how could i deal with it when there are more "|", another situation is that, if it mixes... (2 Replies)
Discussion started by: strugglingman
2 Replies

9. UNIX for Dummies Questions & Answers

Run away "bootpgw" & "inetd"

Hello All. I'm get the following messages posted to the /var/adm/syslog file ever second and not sure on how to stop the process. May 14 15:50:52 a3360 bootpgw: version 2.3.5 May 14 15:50:52 a3360 inetd: /etc/bootpgw exit 0x1 As said about this gets logged every second only thing that... (4 Replies)
Discussion started by: cfaiman
4 Replies

10. UNIX for Dummies Questions & Answers

"./cofigure" and "make" turmoil

I am a Unix newbie and I downloaded some X11 programs. I have gcc, but I cannot compile the files. I NEED HELP!!!! :confused: (16 Replies)
Discussion started by: gnerd
16 Replies
Login or Register to Ask a Question