Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crontab and Scheduling Jobs

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
Using HP/UX 11.0.

I have 3 jobs to schedule, I need them all to run every 30 minutes, spread out by 5 minutes each.

The jobs are due to start at 0500 and run through 2300.

Will this work? Each job must run every 30 minutes. The second job 5 minutes after the first, the third job 5 minutes after the second.

first job :
0,30 5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * * 1-6 /first job to run/

second job :
5,35 5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * * 1-6 /second job to run/

third job :
10,40 5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * * 1-6 /third job to run/

Help is appreciated.
 
Your hour field can be shortened to 5-23.

Also, have you considered running these three jobs from one script?

The script would call the first job. Then, the script would have a sleep command (sleep 300) to wait the 5 minutes. Then the script calls the second job and has another sleep command. Then the script runs the third job and the script ends.

You can put error checking in the script and if any of the jobs fail, the following job wouldn't run and the script would exit. Running the jobs this way would prevent the second and third jobs from running if the job preceding it failed. And you would only have one entry in cron.
 
Have not thought about running from one script, sounds good though.

Might you have an example of the error checking?

Thanks...
 
Scripting is my weakest link. There is a Unix scripting forum (in the Programmers section). You might take a look out there to see if someone can help you.
 
Error checking.

In First job at the end put your message in one file
job1 success
or
job1 error

In second job read that file for error checking
and so on.

Patel
 
Hello!

However, if you need to start the jobs exactly in 5 minute latencies, you should do it some way like this:

...


#start job1 in backgroun
job1 &

#start job2 with 5 mins latency
(sleep 300 ; job2 )&

#start job3 with 10 mins latency
(sleep 600 ; job3 )&

...


If you need state/error checking, creating files as flags seems to be a good idea.

in job 1
...
# the result is succe so put succes flag
touch /tmp/job1_success
...

in job 2
...
# checking if job1 succeeded
if [ -x /tmp/job1_success ] then do_what_you_want_to
...


Enjoy creating scripts :)

--Trifo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top