How to run a process continuously for an hour then stop?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to run a process continuously for an hour then stop?
# 1  
Old 03-17-2014
How to run a process continuously for an hour then stop?

Hi I have a shell script I would like to run it has to run twice a day every 5 seconds for an hour I can do this with cron but I was hoping there was an easier way. Is there a way to make a process sleep only at a certain time of day say between 1 and 2 pm? Or under certain conditions?
Any help you can give me with this would be greatly appreciated
# 2  
Old 03-17-2014
I don't know why you don't like cron try man at

example :
Code:
echo "/usr/bin/ksh /path/to/script/scriptname.ksh" | at 10:30

Code:
at 1030 <<< "/usr/bin/ksh /path/to/script/scriptname.ksh"

# 3  
Old 03-17-2014
Since you want it to run every 5 seconds... for an hour, scheduled twice a day I dont see anything simpler than using cron twice a day, since cron cannot deal with seconds, that part must be done using sleep...
# 4  
Old 03-17-2014
Hi thanks for taking time read my post. Hmm can I set a process to stop with cron? I knew that I could set it to start but if the process continues to run for more than an hour it will cause problems.
Thank you
# 5  
Old 03-17-2014
I think you can keep track of pid of your command

example :
Code:
$ your_command 
$ echo $! >/path/to/pid.file

after some duration you can easily kill it.
# 6  
Old 03-17-2014
Thanks again, I am not really all that familiar with shell programing, but I try to muddle through. Could I set another cron processs an hour latter to stop the running command with out having to find the pid first? can I do it by name only?
Thanks again
# 7  
Old 03-17-2014
Well you could use a loop and a counter : 1 hour every 5 sec, thats 720 executions...
exit once value is reached...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run the script continously but mail once in 1 hour

Hi, I have a script written for monitoring the queue manager status continously. below is the script. QMGR=`dspmq | awk '{print $1}' | cut -f2 -d "(" | cut -f1 -d ")"` QMSTATUS=`dspmq | awk '{print $2}' | cut -f2 -d "(" | cut -f1 -d ")"` count=`dspmq | awk '{print $1}' | cut -f2 -d "(" | ... (5 Replies)
Discussion started by: Anusha M
5 Replies

2. Shell Programming and Scripting

Shell script to be run every one hour

How can we run shell script every one hour. Anyone having code unit for this? (1 Reply)
Discussion started by: Pratiksha Mehra
1 Replies

3. AIX

Run ps aux continuously in AIX

Requirement is to monitor cpu usage /process for a user given time and record the output. topas,topasout,topasrec,tprof not seems to be working for me. so what i am looking for is to run below command continously till the time limit given by the user who runs the script.since below command is a one... (6 Replies)
Discussion started by: NarayanaPrakash
6 Replies

4. Shell Programming and Scripting

To run a job for every one hour and ...

Hi, Someone please help me to run the script to maintain a Job: Which can be run for every one hour and should maintain the last two hours files only. It should delete the rest of the files in a dir. Please suggest me with the sample script. Thanks !! Reagrds, Rama (5 Replies)
Discussion started by: ramagore85
5 Replies

5. Shell Programming and Scripting

How to run script automatically every 12 hour once?

Hi ! all, I have once script to remove temporary cache and temporary xml files looks like this, as it is taking more space, I would like to run automatically every 12 hour once, and then I want to receive some log as acknowledgement #!/bin/sh echo "Removing logs and temp files (typically... (4 Replies)
Discussion started by: Akshay Hegde
4 Replies

6. Shell Programming and Scripting

Need help in running a script continuously non stop

Hi, I am running a schedular script which will check for a specific time and do the job. I wanted to run this continuously. Meaning even after the if condition is true and it executes the job, it should start running again non stop. I am using below script #!/bin/sh start: while true do... (10 Replies)
Discussion started by: sandeepcm
10 Replies

7. Shell Programming and Scripting

Run a script continuously for 10 minutes

Hi all!! Im using ksh and my OS is Linux. I want to run a script for ten minutes, starting from my current system time. How to acheive this? Any help appreciated. Thanks in advance (5 Replies)
Discussion started by: Jayaraman
5 Replies

8. Shell Programming and Scripting

To Run a job every hour without using crontab

Hi, Can anyone help me in finding how to run a specific job every hour without using crontab. Say for example i need to run a command ps -aux in the starting of every hour.. (3 Replies)
Discussion started by: glv
3 Replies

9. Shell Programming and Scripting

how to stop execution of a script after one hour

I have a shell script that writes some data in a file. I want to stop the script after one hour from start of execution using "EXIT 1". how to do it. I don't want to use CRONTAB. (5 Replies)
Discussion started by: mady135
5 Replies

10. Shell Programming and Scripting

Run a script on the hour but only for 30mins

Hi All, I want to run a script on the hour during a 24 - hour period; easy enough cron will take care of that..however I want the script to only run for only 30mins.. so with the script it knows its 30mins are up so exits. any ideas? Any help, greatly appericated. Thanking you all... (2 Replies)
Discussion started by: Zak
2 Replies
Login or Register to Ask a Question