Crontab very useful in Linux schedule Jobs

Source: Internet
Author: User

Crontab is a Linux system integrated scheduled task command, which is useful for system operation (data backup, scheduling system resources or commands, program timing triggering, etc.). Crontab has some task scheduler similar to the service of a Windows system. It can specify a time or time interval for the execution of a background program.

You can install VMware Virtual machine, test the backup of MySQL data, test the timing start of WebService service and so on, maybe you will use Shell programming;

Now, let's talk about the use of crontab:

[Minute] [Hour] [Month] [Year] [Week] [Command]

  

Here are two ways to execute a dispatch command:

First, you create the Systemdate file, the following to >> or in the terminal input #date >/home/systemdate

A, input #crontab-e (not recommended)

For example:   

     * * * * * Date >>/home/systemdate     (query date per minute and recorded in Systemdate file)                                            

B, enter #vim mycron.sh Create the. sh file, edit the following command, and then exit the disk

For example:  

     Date >>/home/systemdate                                                                                                 

Add:

>> means append (for scenario: copying the contents of one file to the end of another)

> means redirect, overwriting the contents of the original file.

    Note: To modify mycron.sh to execute the file 

     chmod 744 mycron.sh                                                                                                       

Let mycron.sh at least be -rwxr--r-- .

1, the following is said, how to add and edit Crontab  

      #crontab-E                                                                                                              

(including the default editor, if your Linux has modified the visual environment variables, then the editor is your count!) )

In the operation of Crontab, is for the user, so please specify the user, of course, if not specified, it must be the default current login user
Crontab-u username

2, list the user's current Crontab

    Crontab-1  

List other users ' crontab

    #crontab-U username-l                                                                                          

3, delete the user's current Crontab

    Crontab-u Username-r

4, Other operations:

    

5, explained from the example, you may see very clearly:

5.1 Execution at some point of the day (once a day), for example, 2:00 per day

      0 2 * * * Date >>/home/systemdate                                                 

5.2 Execution at two times per day (two times a day), e.g. 8:00 night 20:00

       0 8,20 * * * Date >>/home/systemdate

5.3 Execute once every minute

       * * * * * Date >>/home/systemdate     

5.4 A fixed day of the week for a certain moment, for example every week of Monday 8:00 execution

       0 8 * * 1 date >>/home/systemdate

5.5 Executed every 10 minutes

       */10 * * * * Date >>/home/systemdate    

5.6 Let the command be executed only in March, April, 10

       * * * * 3,4,10 * Date >>/home/systemdate    

5.7 A fixed time of day fixed in each week, for example, Monday and Wednesday of each week of 8:00 execution

       0 8 * * 1,3 date >>/home/systemdate

5.8 Executed every four hours

       0 */4 * * * Date >>  /home/systemdate

5.9 Certain two fixed times of a fixed day of the week are executed, for example, Monday and Wednesday of each week 8:00 and 20:00 night

       0 8,20 * * * Date >>/home/systemdate                                         

5.10 executed every 30 seconds

       * * * * * Date >>/home/systemdate * * * * *       sleep 30       

5.11 First minute of the year @yearly = 0 0 1 1 *

       0 0 1 1 * Date >>/home/systemdate   

5.12 first minute of each month @monthly = 0 0 1 * *

0 0 1 * * Date >>/home/systemdate      

5.13 the first minute of every week @weekly = 0 0 1 * *

0 0 1 * * Date >>/home/systemdate

5.14 the first minute of every day @daily = 0 0 * * *

0 0 * * * Date >>/home/systemdate

5.15 The first minute of every hour @hourly = 0 * * * *

0 * * * * Date >>/home/systemdate

There are a lot of Examples, really can not be listed, it is already four o'clock, (for the first time to make the layout so good (compared to me), do a thing really difficult);

  

Crontab very useful in Linux schedule Jobs

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.