-
-
Save amolkhanorkar/9501927 to your computer and use it in GitHub Desktop.
Cron job
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cron | |
Cron is a daemon that executes scheduled commands. Cron is started automatically from /etc/init.d on entering multi-user runlevels. | |
Cron searches its spool area (/var/spool/cron/crontabs) for crontab files (which are named after accounts in /etc/passwd); crontabs found are loaded into memory. | |
Note that crontabs in this directory should not be accessed directly - the crontab command should be used to access and update them. | |
command : crontab -e | |
Cron wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute. | |
Additionally, cron checks each minute to see if its spool directory's modtime (or the modtime on /etc/crontab) has changed, and if it has, cron will then examine the modtime on all crontabs and reload those which have changed. | |
Thus cron need not be restarted whenever a crontab file is modified. Note that the crontab(1) command updates the modtime of the spool directory whenever it changes a crontab. | |
Crontab: | |
Crontab is the program used to install, deinstall or list the tables used to drive the cron daemon in Vixie Cron.Each user can have their own crontab, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. | |
Blank lines and leading spaces and tabs are ignored. Lines whose first non-space character is a hash-sign (#) are comments, and are ignored. | |
The -l option causes the current crontab to be displayed on standard output. | |
The -r option causes the current crontab to be removed. | |
The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables. | |
Crontab Format | |
Commands are executed by cron when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) match the current time. | |
IMPORTANT: | |
A field may be an asterisk (*), which always stands for "first-last". | |
Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive. For example, 8-11 for an "hours" entry specifies execution at hours 8, 9, 10 and 11. | |
Lists are allowed. A list is a set of numbers (or ranges) separated by commas. Examples: "1,2,5,9", "0-4,8-12". | |
Step values can be used in conjunction with ranges. Following a range with "/" specifies skips of the number's value through the range. | |
For example, "0-23/2" can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is "0,2,4,6,8,10,12,14,16,18,20,22"). | |
Steps are also permitted after an asterisk, so if you want to say "every two hours", just use "*/2". | |
“Every four hour i.e. */4” | |
Use the command "crontab -e" to edit your crontab file. | |
Example: | |
# m h dom mon dow command | |
* * * * * curl http://www.example.com/ ------------ run each minute | |
0 */4 * * * curl http://www.example.com/ --------- run in every 4 hour |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment