Linux之定时任务简述
1、日志存放目录
/var/log/cron
2、日志生成
如遇cron无日志生成可以执行一下1、2、3
①、修改rsyslog文件
/etc/rsyslog.d/50-default.conf
将 rsyslog 文件中的 #cron.* 前的 # 删掉;
②、重启rsyslog服务:
service rsyslog restart
③、重启cron服务:
service cron restart
④、查看日志文件:
tail -f /var/log/cron.log
3、创建定时任务
分 、时、天、月、周
定时任务中,脚本的路径需要写绝对路径
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
- 实例1:每1分钟执行一次command or script(绝对路径)
* * * * * command or script(绝对路径)
- 实例2:每小时的第3和第15分钟执行
3,15 * * * * command or script(绝对路径)
- 实例3:在上午8点到11点的第3和第15分钟执行
3,15 8-11 * * * command or script(绝对路径)
- 实例4:每隔两天的上午8点到11点的第3和第15分钟执行
3,15 8-11 */2 * * command or script(绝对路径)
- 实例5:每周一上午8点到11点的第3和第15分钟执行
3,15 8-11 * * 1 command or script(绝对路径)
- 实例6:每晚的21:30重启smb
30 21 * * * /etc/init.d/smb restart
- 实例7:每月1、10、22日的4 : 45重启smb
45 4 1,10,22 * * /etc/init.d/smb restart
- 实例8:每周六、周日的1 : 10重启smb
10 1 * * 6,0 /etc/init.d/smb restart
- 实例9:每天18 : 00至23 : 00之间每隔30分钟重启smb
0,30 18-23 * * * /etc/init.d/smb restart
- 实例10:每星期六的晚上11 : 00 pm重启smb
0 23 * * 6 /etc/init.d/smb restart
- 实例11:每一小时重启smb
0 */1 * * * /etc/init.d/smb restart
- 实例12:晚上11点到早上7点之间,每隔一小时重启smb
0 23-7/1 * * * /etc/init.d/smb restart