Use the crontab command in Linux to regularly execute shell scripts or other Linux commands

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.