Crontab – Quick Reference
1. What is crontab?
Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times.
2.What is a cron job or cron schedule?
Cron job or cron schedule is a specific set of execution instructions specifying day, time and command to execute. crontab can have multiple execution statements.
3. Crontab Commands
export EDITOR=vi ;to specify a editor to open crontab file.
crontab -e Edit crontab file, or create one if it doesn’t already exist.
crontab -l crontab list of cronjobs , display crontab file contents.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)
crontab -l crontab list of cronjobs , display crontab file contents.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)
4. Syntax of crontab
The syntax is:
OR
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)
5. Crontab Examples
1) To run /path/to/command five minutes after midnight, every day, enter:5 0 * * * /path/to/command2) Run /path/to/script.sh at 2:15pm on the first of every month, enter:15 14 1 * * /path/to/script.sh3) Run /scripts/phpscript.php at 10 pm on weekdays, enter:0 22 * * 1-5 /scripts/phpscript.php4) Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am …, everyday, enter:23 0-23/2 * * * /root/scripts/perl/perlscript.pl5) Run /path/to/unixcommand at 5 after 4 every Sunday, enter:5 4 * * sun /path/to/unixcommand
No comments:
Post a Comment