Crontab scheduled job

Source: Internet
Author: User

As long as any user is not included in/etc/cron. deny, he can directly issue "crontab-e" to edit his or her routine commands! As mentioned above, the entire process will go to the VI editing screen and edit it with a work line. After editing, enter ": WQ" to save and Leave Vi! The format of each task is "five time parameter actual action instructions". What are the five time parameters?

 

Meaning Minutes Hours Date Month Week
Number range 0-59 0-23 1-31 1-12 0-7

What's interesting is the week! When the week is 0 or 7, it means "Sunday! In addition, there are some auxiliary characters, which are roughly the following:

 

Special characters Meaning
* Meaning accepted at any time! For example, the example 1 in the above table indicates that the day, month, and week are all *, which means that "the subsequent commands are executed at on every day of the week, no matter what month or day!
, It indicates the meaning of the separated time periods. For example, if you want to release a job at and, it will be:
 

    0, 6 *** command

There are still five columns, but the second column is 3, 6, which indicates that both 3 and 6 are applicable!

- For example, during a period of time, every hour between and has a job:
 

    20 8-12 *** command

The second column is changed to 8-12! It indicates that 8, 9, 10, 11, and 12 are applicable!

/N That N represents the number, that is, the meaning of "every n units interval", for example, once every five minutes, then:
 

    */5 * command

Easy! Use * And/5 together, or enter 0-59/5!

Let's take a look at the exercises with several examples!

 

Example: If your girlfriend's birthday is July 22, May 2 and you want to send a letter to him at on July 22, May 1, the content of this letter has already been written in/home/dmtsai/lover.txt. How can this problem be solved?
A:

    After you directly release crontab-E, edit it:

      59 23 15 * mail Kiki

      In that case, Kiki will receive this letter every year! (Of course, the content of the letter will change every year !)

 

Example: What if/home/dmtsai/test. Sh needs to be executed every five minutes?
A:

    Similarly, use crontab-e to enter the editing page:

      */5 */home/dmtsai/test. Sh

Each crontab has only one file, which is in/var/spool/cron! We also recommend that you: "When the command is down, it is best to use the absolute path, so that the execution file will not be found !』
 

Example: If you have an appointment with a friend on Saturday every week and want to tell your friend not to forget his appointment on Saturday at every Friday, then:
A:

    Still use crontab-e!

      30 16 ** 5 mail friend@his.server.name


Crontab: Command not found

In this case, the system path is not loaded in your shell environment.

Therefore

Source/root/. bash_profile

Source/etc/sysconfig/i18n

Generally run as root:

Crontab-e

Then enter the command:

For example, */5 *** source/etc/profile CD/home/William/chenjilogdigger/; Mongo localhost: 27017/log Stat. js

Save

Note that a job is written as one line,

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.