Centos7 Scheduled Tasks

The cron service is a built-in service of Linux, but it will not start automatically at boot. Services can be started and stopped with the following commands:

/sbin/service crond start
/sbin/service crond stop
/sbin/service crond restart
/sbin/service crond reload
View the user's scheduled tasks:
  crontab -l -u root
  0 */1 * * * command
  0 */2 * * * command

Check the execution of scheduled tasks:

tail -f /var/log/cron

Add tasks:

  crontab -e
  0 */1 * * * command
  0 */2 * * * command

 

Basic format:
* * * * * command
time division day month week command
The first column indicates minutes 1 to 59 every minute is indicated by * or */1
The second column indicates hours 1 to 23 (0 indicates 0 o'clock)
The third column indicates the date 1 to 31
The fourth column indicates the month 1 to 12
The fifth column Identification number week 0~6 (0 means Sunday)
Command to be run in column 6
 
Scheduled task Demo:
 
  
25 21 * * * /sbin/shutdown -h 21:30 
The above example means shutdown at 21:30 every night .
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
The above example means restarting apache at 21:30 every night. 
45 4 1 , 10 , 22 * ​​* /usr/local/etc/rc.d/ lighttpd restart The above example means to restart apache at 4:45 on the 1st, 10th and 22nd of every month. 10 1 * * 6 , 0 /usr/local/etc/rc.d/ lighttpd restart
The above example means to restart apache every Saturday and Sunday at 1:10.
0 , 30 18 - 23 * * * /usr/local/etc/rc.d/ lighttpd restart The above example means to restart apache every 30 minutes between 18:00 and 23:00 every day.
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart The above example means to restart apache every Saturday at 11:00 pm. * */ 1 * * * /usr/local/etc/rc.d/ lighttpd restart
Restart apache every hour
* 23 - 7/1 * * * /usr/local/etc/rc.d/lighttpd restart Restart apache every hour between 11pm and 7am
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart Restart apache on the 4th of every month and every Monday to Wednesday at 11:00
0 4 1 jan * /usr/local/etc/rc.d/ lighttpd restart Restart apache at 4:00 on January 1st

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324981270&siteId=291194637