因为使用频率不高的原因,每次用cron的时候都会被语法格式纠结一下,今天的主题就来梳理一下cron语法和一些使用、调试技巧。
python、ruby
解释器也要写绝对路径source
一下profile文件这里所涉及的命令均在ubuntu14.04下测试过,其它发行版,可以自行Google。没太多理论,直接贴代码了。最后的cron日志存放位置在/var/log/cron.log
cd /etc/rsyslog.d/
sudo vim 50-default.conf
#注释掉这行代码
#cron.* /var/log/cron.log
#重启rsyslog
sudo service rsyslog restart
# 重启cron
sudo service cron restart
跟我一样属于视觉学习型选手的同学有福了,一图胜千言,需要的就收藏起来吧。
* * * * * myCommand
3,15 * * * * myCommand
3,15 8-11 * * * myCommand
3,15 8-11 */2 * * myCommand
3,15 8-11 * * 1 myCommand
30 21 * * * /etc/init.d/smb restart
45 4 1,10,22 * * /etc/init.d/smb restart
10 1 * * 6,0 /etc/init.d/smb restart
0,30 18-23 * * * /etc/init.d/smb restart
0 23 * * 6 /etc/init.d/smb restart
* */1 * * * /etc/init.d/smb restart
* 23-7/1 * * * /etc/init.d/smb restart
-完-