码迷,mamicode.com
首页 > 其他好文 > 详细

Centos7 定时任务

时间:2018-04-27 21:17:05      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:code   color   linu   http   日期   /etc/   local   span   ice   

cron服务是Linux的内置服务,但它不会开机自动启动。可以用以下命令启动和停止服务:

/sbin/service crond start
/sbin/service crond stop
/sbin/service crond restart
/sbin/service crond reload
查看用户的定时任务:
  crontab -l -u root
  0 */1 * * * command
  0 */2 * * * command

查看定时任务的执行情况:

tail -f /var/log/cron

增加任务:

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

 

基本格式 :
*  *  *  *  *  command
分 时 日 月 周 命令
第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令
 
定时任务Demo:

25 21 * * * /sbin/shutdown -h 21:30
上面的例子表示每晚的21:30关机。
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每晚的21:30重启apache。
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart 上面的例子表示每月1、10、22日的4 : 45重启apache。
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart 上面的例子表示每周六、周日的1 : 10重启apache。
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart 上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启apache。
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart 上面的例子表示每星期六的11 : 00 pm重启apache。
* */1 * * * /usr/local/etc/rc.d/lighttpd restart 每一小时重启apache
* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart 晚上11点到早上7点之间,每隔一小时重启apache
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart 每月的4号与每周一到周三的11点重启apache
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart 一月一号的4点重启apache

 

Centos7 定时任务

标签:code   color   linu   http   日期   /etc/   local   span   ice   

原文地址:https://www.cnblogs.com/Huluwa-Vs-Aoteman/p/8964186.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!