Crontab Schedule
Crontab Schedule
Go into your crontab file
sudo crontab -l
sudo crontab -e
Scheduling format
* * * * * /bin/execute/this/script.sh
The *
meaning in different position
Position (From left to right) | Description | Range |
---|---|---|
1 | Minute | 0-59 |
2 | Hour | 0-23 |
3 | nth day of the month | 1-31 |
4 | nth month of the year | 1-12 |
5 | day of the week | 0-6, 0: Sunday |
The
*
means it will match in every time when run the crontab command
Special Character
@reboot Run 1 time when reboot
@yearly Run 1 time every year "0 0 1 1 *"
@annually (Same as @yearly)
@monthly Run 1 time every month "0 0 1 * *"
@weekly Run 1 time every week "0 0 * * 0"
@daily Run 1 time every day "0 0 * * *"
@midnight (Same as @daily)
@hourly Run 1 time every hour "0 * * * *"
Output your command result to garbage collection and show nothing
*/10 * * * * /bin/execute/this/script.sh > /dev/null 2>&1
Test crontab
You can run the crontab
command directly to make sure that every setting in the crontab file
is correct.
crontab path/to/crontab/file
If there is some setting wrong in the crontab file
, then it will show the error message.
"/etc/crontab":165: bad day-of-month
errors in crontab file, can\'t install.
Reference
- Schedule Tasks on Linux Using Crontab | kvz.io
- Crontab.guru - The cron schedule expression editor
- cron - Is there a way to validate /etc/crontab’s format? - Server Fault