With Crontab you can execute a shell script or a series of Linux commands at a specified time. For example, the system administrator schedules a backup task to run every day
How do I add a job to cron?
# crontab–e
0 5 * * */root/bin/backup.sh
This will run at 5 o '/root/bin/backup.sh every morning.
Description of Cron Items
The following is the format of the crontab file:
{minute} {Hour} {Day-of-month} {Month} {Day-of-week} {Full-path-to-shell-script}
O minute: Interval is 0–59
O Hour: Interval is 0–23
O Day-of-month: Interval is 0–31
O Month: The interval is 1–12. 1 was January. 12 was December.
O Day-of-week: Interval is 0–7. Sunday can be 0 or 7.
Crontab Example
1. Run at 12:01 a.m., which is a minute every morning. This is an appropriate time to make a backup, because the system is not loaded at this point.
1 0 * * */root/bin/backup.sh
2. The backup job is performed every weekday (MON–FRI) 11:59 p.m.
* * 1,2,3,4,5/root/bin/backup.sh
The following example has the same effect as the example above:
* * 1-5/root/bin/backup.sh
3. Run the command every 5 minutes
*/5 * * * */root/bin/check-status.sh
4.1:10 p.m. on the first day of each month
1 * */root/bin/full-backup.sh
5. Run every weekday.
0 * * 1-5/root/bin/incremental-backup.sh
Crontab Options
The following are the valid options for crontab:
Crontab–e: Modify the crontab file. If the file does not exist, it is created automatically.
Crontab–l: Displays the crontab file.
Crontab-r: Delete the crontab file.
Crontab-ir: Alerts the user before deleting the crontab file.
The above is the specific use of the crontab command.
16 monitoring commands for Linux servers