With crontab, You can execute a shell script or a series of Linux commands at the specified time. For example, the system administrator schedules a backup task to run on a daily basis.
How do I add a job to cron?
# Crontab-e
0 5 ***/root/bin/backup. sh
This will run/root/bin/backup. sh at every morning.
Cron description
The format of the crontab file is as follows:
{Minute} {hour} {day-of-month} {day-of-week} {full-path-to-shell-script}
O minute: the interval is 0-59.
O hour: the range is 0-23.
O day-of-month: the range is 0-31
O month: the range is 1-12. 1 is January. 12 is December.
O Day-of-week: the range is 0-7. Sunday can be 0 or 7.
Crontab example
1. Run at A.M, that is, one minute every morning. This is an appropriate backup time, because the system load is not large at this time.
1 0 ***/root/bin/backup. sh
2. A backup job is performed every workday (Mon-Fri) at p.m.
59 11 ** 1, 2, 4, 5/root/bin/backup. sh
The following example has the same effect as the above example:
59 11 ** 1-5/root/bin/backup. sh
3. Run the command every five minutes.
*/5 */root/bin/check-status.sh
4. Run P.M. on the first day of each month.
10 13 1 */root/bin/full-backup.sh
5. Run the program on 11 p.m. every working day.
0 23 *** 1-5/root/bin/incremental-backup.sh
Crontab Option
The following are valid crontab options:
O crontab-e: Modify the crontab file. It is automatically created if the file does not exist.
O crontab-l: displays the crontab file.
O crontab-r: Delete the crontab file.
O crontab-ir: notifies the user before deleting the crontab file.
The preceding figure shows how to use the crontab command.