Centos7: Uses crontab to regularly execute tasks. centos7crontab
The cron service is a built-in service in Linux, but it does not start automatically when it is started. Run the following command to start and stop the service:
/sbin/service crond start
/sbin/service crond stop
/sbin/service crond restart
/sbin/service crond reload
The preceding lines start, stop, restart the service, and reload the configuration.
Set the cron to automatically start when it is started, and add it to the/etc/rc. d/rc. local script./sbin/service crond start
You can.
View the current user's crontab and enter crontab-l;
Edit crontab and enter crontab-e;
Delete crontab and enter crontab-r.
Add task
crontab -e 0 */1 * * * command 0 */2 * * * command
Check whether the task has been added:
Crontab-l-u root # view the root user 0 */1 *** command 0 */2 *** command
Basic Format:
* *** Command
Minute, day, month, week, command column 1st indicates minute 1 ~ 59. Each minute is represented by * or */1.
The first column indicates the hour 1 ~ 23 (0 indicates 0 points)
The 3rd column indicates the date 1 ~ 31
The 4th column indicates the month 1 ~ 12
The Identification Number of column 5th is from day of the week to day ~ 6 (0 indicates Sunday)
Example of the crontab file to be run in column 6th: 30 21 ***/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates restarting apache at every night. 45 4, 10, 22 **/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted at on the 1st, 10th, and 22th every month. 10 1 ** 6, 0/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted at every Saturday and Sunday. 0, 30 18-23 ***/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted every 30 minutes between and every day. 0 23 ** 6/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted at every Saturday. **/1 ***/usr/local/etc/rc. d/lighttpd restart
Restart apache ** 23-7/1 ***/usr/local/etc/rc. d/lighttpd restart every hour
Restart apache0 11 4 * mon-wed/usr/local/etc/rc. d/lighttpd restart from PM to PM.
Restart apache0 4 1 jan */usr/local/etc/rc. d/lighttpd restart at every Monday to Wednesday.
Restart apache at on January 1, January 1