cron是一个Linux定时执行工具,要把cron设为在开机的时候自动启动,在 /etc/rc.d/rc.local 脚本中加入 /sbin/service crond start
cron 服务的启动与停止,命令如下:
- service cron start /*启动服务*/
- service cron stop /*关闭服务*/
- service cron restart /*重启服务*/
- service cron reload /*重新载入配置*/
- service cron status /*查看crond状态*/
crontab命令
- 查看当前用户的crontab,输入 crontab -l;
- 编辑crontab,输入 crontab -e;
- 删除crontab,输入 crontab -r
crontab文件示例
- 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/lig