A, crond
cron is a linux under the regular implementation of the tool (equivalent to the scheduled task under windows), it can periodically run task task without the need for manual intervention.
Since cron is a Linux-service (deamon), you can start with the following methods to close this 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
Start automatically when the system starts:
In /etc/rc.d/ the end of the rc.local script plus:
/ sbin / Service crond Start
Two, crontab
cron service providers to set the cron crontab command service
crontab -u // set a user's cron service, usually root user needs at this time to execute the command parameter crontab the -l // set out in detail the contents of a user cron services crontab -r // remove a user the service cron crontab -e // edit a user's cron service
example
root view their own cron settings: crontab -u root - L root you want to delete the cron setting fred: crontab -u fred - r When editing the cron service, edit the contents of some of the formats and conventions, enter: crontab -u root -e // enter vi edit mode, edit the content must meet the following format:
* / 1 * * * * LS >> /tmp/ls.txt
before // part of the setting for the time, to be executed later part command
*/1 * * * * ls >> /tmp/ls.txt
* The first five numbers represent the five numbers in the range and meaning of the numbers are as follows:
Minute (0-59 ) hour (0 -23 ) date ( 1-31 ) month ( 1-12 ) week (0 -6) // 0 for Sunday * on behalf of all the numbers in the range of " / " representing each meaning, " * / 5 " means every 5 units " - " represents the numbers from one to a digital " , " separate several discrete digital
Examples
// daily from 6 am 0 6 * * * echo " Good Morning. " >> / tmp / test.txt // every two hours 0 * / 2 * * * echo " Have A BREAK now. " >> / tmp / test.txt // 4 and each week Monday to Wednesday of each month at 11:00 am 0 11 4 * 1-3 the Command Line // 1 January 4 am 0 4 1 1 * the Command line
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
the example above indicates night 21:30 restart lighttpd.
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
the above example is 1, 10, 422 days per month: 45 restart lighttpd.
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
the above examples represent every Saturday, Sunday 1: 10 to restart lighttpd.
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
the above example are shown in day 18: 00-23: 00 every 30 minutes to restart lighttpd.
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
the above examples represent every Saturday in 11: 00 pm restart lighttpd.
* * / 1 * * * /usr/local/etc/rc.d/lighttpd restart
every hour restart lighttpd
* * * * 23-7 / 1 /usr/local/etc/rc.d/lighttpd restart
between 11 pm to 7 am, every hour restart lighttpd
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
the monthly number 4 and 11:00 from Monday to Wednesday to restart lighttpd
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
January 1st of 4:00 to restart lighttpd
This generates a file with the same name as the user after each finished editing a user's cron settings, cron automatically at / var / spool / cron, cron this user information is recorded in this file, this file is not directly edited and you can only be edited with crontab -e. After cron starts every time a bell reading this document, check whether the command to be executed inside. So after modifying this file does not need to restart the cron service.