Linux uses the crontab command to execute shell scripts or other Linux commands on a timed basis

Source: Internet
Author: User
Tags crontab example

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

Related Article

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.