0×01:crontab、
crontab 是一个用于设置周期性被执行的任务工具
周期性执行的任务列表称为Cron Table
0×02:crontab常用参数
-e:编辑该用户的计时器设置
-l:列出该用户的计时器设置
-r:删除该用户的计时器设置
-u:指定要设定计时器的用户名称
0×03:安装crontab、
yum install crontabs
0×04:crontab服务操作
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
0×05:crontab 配置文件格式
# .—————- 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
0×06:crontab 案例
每晚的21:30重启apache
30 21 * * * service httpd restart
每月1、10、22日的4:45重启apache
45 4 1,10,22 * * service httpd restart
每月1到10日的4:45重启apache
45 4 1-10 * * service httpd restart
每隔两分钟重启apache
*/2 * * * * service httpd restart
1-59/2 * * * * service httpd restart
晚上11点到早上7点之间,每隔一小时重启apache
0 23-7/1 * * * service httpd restart
每天18:00至23:00之间每隔30分钟重启apache
0,30 18-23 * * * service httpd restart
0-59 18-23 * * * service httpd restart
0×06:小结
*表示任何时候都匹配
用“A,B,C”表示A或者B或者C时执行命令
“A-B”表示A-B之间时执行命令
“*/A”表示每A分钟(小时等)执行一次命令