Crontab let Linux execute shell scripts at timed intervals

Source: Internet
Author: User
Tags system log

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

Entry

# crontab–e

This allows you to open your personal crontab profile in edit mode and then add this line:

XX * * * */home/linrui/xxxxxxxx.sh

This will run the specified. sh file at 00:00 every day.

For scripts that resemble a few minutes of execution, add ">/dev/null 2>&1" at the end, which indicates that the system log is not written:

XX * * * */home/linrui/xxxxxxxx.sh >/dev/null 2>&1

Cron description of each item

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 00:01

* * * */home/linrui/xxxx.sh

2, the backup job every weekday 23:59.

* * 1,2,3,4,5/home/linrui/xxxx.sh

or the following:

* * 1-5/home/linrui/xxxx.sh

3. Run a command every minute

*/1 * * * */home/linrui/xxxx.sh

4, 1th number 14:10 per month to run

* */home/linrui/xxxx.sh

Crontab Options for Commands

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.

Reprinted from: https://my.oschina.net/u/2288038/blog/485972

Crontab let Linux execute shell scripts at timed intervals

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.