I. cron Introduction
Cron is a scheduled execution tool in Linux. It is equivalent to a scheduled task in windows, and cron is a service (deamon) in Linux. Therefore, you can run the following command to disable the service:
/Sbin/service crond start // start the service
/Sbin/service crond stop // close the service
/Sbin/service crond restart // restart the service
/Sbin/service crond reload // reload the configuration
Set automatic start upon startup: Add/sbin/rc. d/rc. Local to the end of the script/etc/rc. d/rc. Local.
Ii. crontab command of Cron
The cron Service provides the crontab command to set the cron service. Some commands are as follows:
Crontab-u // set a user's cron service. Generally, the root user needs this parameter when executing this command.
Crontab-l // list the details of a user's cron Service
Crontab-r // delete a user's cron Service
Crontab-E // edit a user's cron Service
Command Format: crontab-u username parameter
When editing the cron service, run the *** command in the following format:
Minute hour 0-23 Date 1-31 month week 0-6 command is long, you can write a script, directly call the script, but use the absolute path
In addition to numbers, there are also several symbols: * All values in the value range/each (*/5 each 5 units)-from a number to a number, several discrete numbers
For example, 0 6 * echo "output at 6 o'clock every morning">/tmp/test.txt // No output is displayed on the pure echo screen. The Cron should send any output email to the root mailbox.
After a user's cron settings are edited, cron automatically generates a file with the same name under/var/spool/cron, the cron information of this user is recorded in this file. This file cannot be edited directly. You can use crontab-e to edit it. The cron reads the file every minute after it is started, and checks whether to execute the commands in it. Therefore, you do not need to restart the cron service after the file is modified.
Iii. cron configuration file
The cron system-level configuration file is located in/etc/crontab. The Cron service not only reads all files in/var/spool/cron every minute, but also reads the/etc/crontab configuration file once, therefore, you can use the cron service to configure the file. Crontab-E is configured for a user, while/etc/crontab is for system tasks.
Shell =/bin/bash
Path =/sbin:/bin:/usr/sbin:/usr/bin
Mailto = root // if an error occurs or data is output, the data is sent to this account as an email.
Home = // path of the user running. The root directory is used here.
Example: 42 4 1 ** root run-parts/etc/cron. monthly // run/etc/cron every month. the script in monthly (all scripts in the folder) "Run-parts". Remove this parameter and write the script name to be run later, instead of the folder name.
4. Special usage (@)
@ Hourly/usr/local/www/AWStats/cgi-bin/AWStats. Sh (0 *****) in addition
String meaning ------ ------- @ reboot run once, at startup. @ yearly run once a year, "0 0 1 *". @ annually (same as @ yearly) @ monthly run once a month, "0 0 1 **". @ weekly run once a week, "0 0 ** 0 ". @ daily run once a day, "0 0 ***". @ midnight (same as @ daily) @ hourly run once an hour, "0 ****".
Reference: http://www.cnblogs.com/itech/archive/2011/02/09/1950226.html
Cron scheduled task