How to Use cron for regular tasks

Source: Internet
Author: User
How to Use crontab for regular tasks

[Precondition]

OS: RedHat fedora 2

 

[Brief introduction]

CronIs a daemon task to allow others tasks to be automatically run at the regular interval. cron then wakes up every minute, and examining all crontab files stored, and checking each command to see whether it shocould be run in the current minute. when executing commands, any output is mailed to the owner of the crontab or the user named in the mailto environment variable in the crontab, if such exists.

CrontabMaintains crontab files for individual users, so we can useCrontabCommand to edit/remove/list crontab files.

 

[Crontab commands]

Crontab-e edit crontab file, or create one if it doesn't already exist.

Crontab-l display your crontab file.

Crontab-r remove your crontab file.

Crontab-u the user of crontab, if no-u option, it means to use current login user.

 

[Format of crontab file]

* *** Command to be executed

|

| + ----- Day of week (0-7) (Sunday = 0/7)

| + ------- Month (1-12)

| + --------- Day of month (1-31)

| + ----------- Hour (0-23)

+ ------------- Minute (0-59)

* In the value field above means all legal values as in braces for that column. the value column can have a * or a list of elements separated by commas. an element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range ).

For example:

*/2 ***** echo 'append me'>/tmp/tmp.txt

It means that 'append me' will be appended into/tmp/tmp.txt every minute. '2' is step, and it can be used front five time elements.

 

*/2 1, 3, 5 * echo 'append me'>/tmp/tmp.txt

Only at 1th, 3th, 5th hour will append 'append me' into/tmp/tmp.txt every minute.

In words, we can use shell scripts to do something and add running commands into cron daemon to do at the background. So crontab-e shoshould be used directly.

 

[How to start/stop/restart cron]

# Service crond start/stop/restart

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.