niedziela, 13 stycznia 2013

How to schedule Cron to run jobs every 5 Minutes, 12 hours, etc.


Linux Crontab Format
MIN HOUR DOM MON DOW CMD

Schedule a job for more than one instance (e.g. twice a day)

Below example executes the specified script (send_reports.rb) at 10:00 and 16:00 on every day. The comma separated value in a field specifies that the command needs to be executed in all the mentioned time.
00 10,16 * * * ruby /home/luke/scripts/send_reports.rb
00 – 0th Minute (Top of the hour)
10,16 – 10 AM and 4 PM
* – Every day
* – Every month
* – Every day of the week

Schedule a job for specific range of time (e.g. only on weekdays)

To schedule a job to be ran for every hour with in a specific range of time then use the following. This example checks the status of the server everyday (including weekends) during the working hours 10 a.m – 3 p.m
00 10-15 * * * ruby /home/luke/scripts/check-server-status.rb
00 – 0th Minute (Top of the hour)
10-15 – 10 am,11 am, 12 am, 1 pm, 2 pm, 3 pm
* – Every day
* – Every month
* – Every day of the week

Execute a job every 5 minutes

*/5 * * * * /home/luke/scripts/do_work.sh
In the same way, use */10 for every 10 minutes, */15 for every 15 minutes, */30 for every 30 minutes, etc.

Execute a job every 5 hours

0 */5 * * * /home/luke/scripts/backup.sh
In the same way, use */2 for every 2 hours, */3 for every 3 hours, */4 for every 4 hours, etc. Table: Cron special keywords and its meaning
Keyword Equivalent
@yearly 0 0 1 1 *
@daily 0 0 * * *
@hourly 0 * * * *
@reboot Run at startup.

Schedule a job for first minute of every year using @yearly

When you want a job to be executed on the first minute of every year, then you can use the @yearly cron keyword in way shown below.
@yearly /home/luke/scripts/sell-db-annual-maintenance
This configuration execute the financial database annual maintenance using sell-db-annual-maintenance shell script at 00:00 on Jan 1st for every year.

Schedule a background job every day using @daily

Use the @daily cron keyword to do a daily backup file using backup-invoices shell script at 00:00 on every day.
@daily /home/luke/scripts/backup-invoices "day started"

Brak komentarzy:

Publikowanie komentarza