Total Pageviews

Saturday, August 9, 2014

setting up cronjob what each number means



Syntax of crontab (Field Description)


For user jobs, cron job looks as follows:

1 2 3 4 5 /path/to/command arg1 arg2

OR

1 2 3 4 5 /root/backup.sh

Where,

  • 1: Minute (0-59)
  • 2: Hours (0-23)
  • 3: Day (0-31)
  • 4: Month (0-12 [12 == December])
  • 5: Day of the week(0-7 [7 or 0 == sunday])



  • /path/to/command - Script or command name to schedule

Easy to remember format:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

For system jobs, cron job looks as follows:

1 2 3 4 5 USERNAME /path/to/command arg1 arg2

OR

1 2 3 4 5 USERNAME /path/to/script.sh

 

Crontab Shortcut Command -Using Special String to Save Time


Instead of the first five fields, you can use any one of eight special strings listed below. It will not only save your time but it will improve readability.

Special string
Meaning
@reboot
Run once, at startup.
@yearly
Run once a year, "0 0 1 1 *".
@annually
(same as @yearly)
@monthly
Run once a month, "0 0 1 * *".
@weekly
Run once a week, "0 0 * * 0".
@daily
Run once a day, "0 0 * * *".
@midnight
(same as @daily)
@hourly
Run once an hour, "0 * * * *".

IMPORTANT:

·        Run ntpdate every hour by using the command, @hourly /path/to/ntpdate


·        Make a backup everyday by using the command, @daily /path/to/backup/script.sh

No comments:

Post a Comment