Set scheduled tasks in Linux

Source: Internet
Author: User

In normal work, you often encounter some routine tasks that need to be run regularly on a daily basis. To solve this problem, you can use the crontab command. Let's take a look at it later ~

First, start the crontab service.

 

Service crond start # Start the service
Service crond stop # disable the service
Service crond restart # restart the service
Service crond reload # reload Configuration

 

 

Then, use crontab-e to edit the routine task, save the task, and exit.

The specific format is described as follows:

The format of each line is: hour, day, month, week

The 1st column indicates minute 1 ~ 59. Each minute is represented by * or */1.
The first column indicates the hour 1 ~ 23 (0 indicates 0 points)
The 3rd column indicates the date 1 ~ 31
The 4th column indicates the month 1 ~ 12
The Identification Number of column 5th is from day of the week to day ~ 6 (0 indicates Sunday)
6th columns of commands to run

 

It is worth noting that in crontabWhether the command or file path must be fully writtenOtherwise, it is not recognized.

For example, to execute a/home/run/test. Sh script at every day, you can configure it as follows:

0 6 ***/sbin/SH/home/run/test. Sh

Or

0 6 * CD/home/run &/bin/sh test. Sh

Note that the command in the test. Sh script also needs to use the full path; otherwise, crontab cannot be found.

If you want to have other requirements, such as retaining the output, you can redirect the output, which is no different from running a Normal script.

 

0 6 * CD/home/run &/bin/sh test. Sh> log

 

 

 

 

 

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.