Use crontab to define scheduled tasks

Source: Internet
Author: User

Crontab uses the cron service to enable users to execute certain programs at a specified time. It uses cron to copy, create, and delete crontab files to manage user permissions and plans.
Command Format: crontab [-u username] [-L] [-E] [-R]
Option description:
-E: edit the current user's crontab file, or create a crontab file when a crontab file does not exist. After editing and saving the file, it is installed by the current user's crontab.
-L list the contents of the current crontab file.
-R: Delete the crontab file of the current user.
-U Username: Specifies the user name.
Crontab file format:
The crontab file has six fields separated by spaces or the tab key. The first five fields are integers or *. The format is as follows (the value range is in parentheses ):
Minute (0-59) hour (0-23) Day (1-31) month (1-12) Week (0-6) command to be executed
The week value 0 indicates Sunday, and the other values are recursive. In the first five domains, each domain can use * to indicate all valid values, or use a list to list valid values, separated, you can also use "-" to indicate a range. The following command demonstrates how to run/home/wuxp/backup. Sh every week from Sunday to Thursday.
30 23 ** 0-4/home/wuxp/backup. Sh
The following example shows how to clear core files in the user directory from Monday to Friday.
15 3 ** 1-5 find $ home-name Core 2>/dev/null | xargs Rm-F
The following is an example of a crontab file. Use the crontab-e command to edit it.
Path =/usr/bin:/usr/sbin:/sbin
Home =/home/wuxp
30 23 ** 0-4/home/wuxp/backup. Sh
The first four lines define the environment variables, and the last line is the executed command. You can define to execute multiple commands. If your crontab file has been correctly edited, you will get a message "crontab: Installing new crontab" after saving and exiting.
Related Files:
/Etc/cron. allow if the file exists, you can use crontab for the username contained in the file.
/Etc/cron. deny if the file exists, users in the file cannot use crontab.
You can edit these two files by yourself. Note that each user name occupies one row.

TIPS:

Crontab-e only insert line into crontab file, you must execute command "crontab crontab_file". If you login with "root", command line is "crontab root ".
All crontab files are in directory "/usr/spool/cron/crontabs ".
And the detail please "Man crontab ".

I couldn't find the above directory, So I restarted the crond service.
/Etc/rc. d/init. d/crond 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.