Linux System Command Learning Series-timed Task crontab command

Source: Internet
Author: User

Previous section review:

1. Use of the AT command

2. Job: Create a task 10 minutes after shutdown

At now+10 minutes

At>shutdown

At><eot>

In this section we proceed to the second command of the routine task management command: Cron

Before using the command, see if the Crond service is turned on

Service Crond Status

If it is not turned on, it can be opened with service Crond start

Note: Some Linux system service Cron status to view.

1. Editing Task Crontab–e

The format of the crontab command is as follows

* * * * * command

This format is preceded by 5 * followed by a command to execute

The meanings of 5 stars are:

The first *, representing minutes, 1-59, per minute can be expressed in * and */1

The second *, representing the hour, 0-23

The third *, which represents a date, 1-31

Fourth *, indicating the month, 1-12

Fifth *, representing the week, 0-6,0 said Sunday

Here are some examples to illustrate

* * * * * echo ' hello ' >>/tmp/test.txt

*/1 * * * * echo ' hello ' >>/tmp/test.txt

The above indicates that the output of Hello is executed every minute and the output is written to the/tmp/test.txt file

After you save the exit, you can see that the hello is output in the/tmp/test.txt

More examples:

* */1 * * * echo ' hello ' >>/tmp/test.txt

Indicates hourly execution

* 23-3/1 * * * echo ' hello ' >>/tmp/test.txt

Indicates that 23 to 3 points are executed every hour.

* * * echo ' hello ' >>/tmp/test.txt

To be executed 8:30 every night.

1 * * echo ' hello ' >>/tmp/test.txt

Indicates 1th # 10:10 per month to perform operations

1 1 * echo ' hello ' >>/tmp/test.txt

Represents an operation on January 1 10:10 every year

Ten * * 1 echo ' Hello ' >>/tmp/test.txt

Represents every Monday 10:10 operation

2. View Task Crontab–l

Use Crontab–l to see all your custom tasks

The command exists in the/var/spool/cron/root file

3. Delete All Tasks Crontab–r

Use Crontab–r to delete all custom tasks

4. System built-in timer task

Below the/etc/you can see

There are cron.daily,cron.hourly,cron.monthly,cron.weekly folders that represent the daily, hourly, monthly, and weekly scheduled tasks to be performed by the system. Take one of these as an example to see the system's timing tasks

Job: Define a timed task that outputs Hello world to the/tmp/test.txt file every minute


Follow the public number "get kicked genius" for free video tutorials


Linux System Command Learning Series-timed Task 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.