Aman
Aman

Reputation: 3261

Scheduling in Cron tab for regular interval

Hi I have 2 jobs where 2nd job needs to run 30 min after 1st job.

I am using crontab -e to setup cron job

1st job     0 * * * * /home/hadoop/datapull.sh
2nd job  /home/hadoop/loaddata.sh 

I have scheduled my 1st job (datapull.sh) like above which will run evrey hour.

Subsequently my 2nd job needs to run after 30 min of completion of 1st job.

Lets say my 1st job runs 1PM,2PM,3PM,4PM so on and my second job should be around 1.30PM,2.30PM,3.30PM,4.30PM . 

How can I schedule my 2nd job to in cron tab to setup like this. Ned help for setting up cron tab.

Upvotes: 0

Views: 2047

Answers (2)

Ali Al-arnous
Ali Al-arnous

Reputation: 137

the first job should be start at minute 0 from each hour like
1st job 0 * * * * /home/hadoop/datapull.sh
as you wrote
but second job must be start at minute 30 like :
2nd job 30 * * * * /home/hadoop/loaddata.sh

best regards

Upvotes: 2

baao
baao

Reputation: 73241

Second job:

30 * * * *  /home/hadoop/loaddata.sh 

This will run your cronjob, f.e. on 0:30, 1:30, 2:30, 3:30, ...


This is how a cronjob is setup in general:

 # * * * * *  command to execute
 # │ │ │ │ │
 # │ │ │ │ │
 # │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
 # │ │ │ └────────── month (1 - 12)
 # │ │ └─────────────── day of month (1 - 31)
 # │ └──────────────────── hour (0 - 23)
 # └───────────────────────── min (0 - 59)

What does Asterisk (*) mean

The asterisk indicates that the cron expression matches for all values of the field. E.g., using an asterisk in the 4th field (month) indicates every month.


Sidenote

Other special characters in cronjobs

Slash ( / )

Slashes describe increments of ranges. For example 3-59/15 in the 1st field (minutes) indicate the third minute of the hour and every 15 minutes thereafter. The form "*/..." is equivalent to the form "first-last/...", that is, an increment over the largest possible range of the field.

Comma ( , )

Commas are used to separate items of a list. For example, using "MON,WED,FRI" in the 5th field (day of week) means Mondays, Wednesdays and Fridays.

Hyphen ( - )

Hyphens define ranges. For example, 2000-2010 indicates every year between 2000 and 2010 AD, inclusive.

Percent ( % )

Percent-signs (%) in the command, unless escaped with backslash (), are changed into newline characters, and all data after the first % are sent to the command as standard input.

See http://en.m.wikipedia.org/wiki/Cron

Upvotes: 2

Related Questions