IT/Software/System Config/cron: Difference between revisions
(Created the page) |
mNo edit summary |
||
Line 15: | Line 15: | ||
The following line would execute script.sh at minute 0 of the 8th hour, every day, every month and every day of the week. | The following line would execute script.sh at minute 0 of the 8th hour, every day, every month and every day of the week. | ||
Or in simpler terms it runs | Or in simpler terms, it runs every day at 8:00 AM. | ||
0 8 * * * /path/to/script.sh | 0 8 * * * /path/to/script.sh | ||
Now | Now let's say we want to run our script every 5 minutes. | ||
We could try doing the following but that would | We could try doing the following but that would only run the script 5 minutes after every hour. | ||
5 * * * * /path/to/script.sh | 5 * * * * /path/to/script.sh | ||
In cron we can use the "/" character to indicate step values so to run every 5 minutes we can do the following. | In cron we can use the "/" character to indicate step values so to run every 5 minutes we can do the following. | ||
Line 25: | Line 25: | ||
=== Special times === | === Special times === | ||
Cron also has several special times | Cron also has several special times that can be used in place of the regular time format. | ||
For the following the script will be run on the first minute of the selected time frame. | For the following, the script will be run on the first minute of the selected time frame. | ||
* @yearly | * @yearly | ||
Line 35: | Line 35: | ||
* @hourly | * @hourly | ||
So for example to run at minute 0 of every hour we can do the following. | So, for example, to run at minute 0 of every hour we can do the following. | ||
@hourly /path/to/script.sh | @hourly /path/to/script.sh | ||
We also have one more special time to run scripts at reboot. | We also have one more special time to run scripts at reboot. | ||
* @reboot | * @reboot |
Revision as of 16:28, 18 March 2020
About
Cron is a "daemon to execute scheduled commands"[1]
Usage
To edit your crontab you can run
crontab -e
Formatting
Cronjobs are in typically in the following format
* * * * * /path/to/script.sh
The time is in the format of
Minute, Hour, Day of the month, Month, Day of the week.
The following line would execute script.sh at minute 0 of the 8th hour, every day, every month and every day of the week.
Or in simpler terms, it runs every day at 8:00 AM.
0 8 * * * /path/to/script.sh
Now let's say we want to run our script every 5 minutes.
We could try doing the following but that would only run the script 5 minutes after every hour.
5 * * * * /path/to/script.sh
In cron we can use the "/" character to indicate step values so to run every 5 minutes we can do the following.
*/5 * * * * /path/to/script.sh
Special times
Cron also has several special times that can be used in place of the regular time format.
For the following, the script will be run on the first minute of the selected time frame.
- @yearly
- @monthly
- @weekly
- @daily
- @hourly
So, for example, to run at minute 0 of every hour we can do the following.
@hourly /path/to/script.sh
We also have one more special time to run scripts at reboot.
- @reboot