Frank的学习之路

crontab配置

定时任务,一般默认启动

service crond restart       //启动crond服务
chkconfig crond on         //开机启动,默认开机启动
ps aux|grep crond          //检查crond是否启动


编辑命令:

crontab -e                 //编辑定时任务
crontab -l                 //查看定时任务
crontab -r                 //删除所有定时任务

设置定时时间

基本格式 :
 *      *   *   *   *  command
分 时 日 月 周         命令

# Use the hash sign to prefix a comment
# +—————- minute (0 – 59)
# | +————- hour (0 – 23)
# | | +———- day of month (1 – 31)
# | | | +——- month (1 – 12)
# | | | | +—- day of week (0 – 7) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed

* //表示任意时间  ,//表示不连续时间  .//表示连续时间 */n //表示每隔多久执行一次


设置举例:

* * * * *  每分钟执行
*/1 * * * *  每分钟执行
0 5 * * * 每天五点执行
0-59/2 * * * * 每隔两分钟执行,且是偶数分钟执行,比如2,4,6
1-58/2 * * * * 每隔两分钟执行,且是奇数分钟执行,比如3,5,7
0 0 1,5,10 * * 每个月1号,5号,10号执行

0 0 1-5 * * 每个月 1到5号执行

45 22 * * *    //每天10点45执行命令
0 17  * * 1    //每周1的下午5点执行命令
10 * * * *     //每个小时第10分钟执行一次
5 5 * * 2 /sbin/shutdown -r now
0 5 * * 2 //root/sh/mysqlback.sh

30 21 * * * /etc/init.d/nginx restart
每晚的21:30重启 nginx。

45 4 1,10,22 * * /etc/init.d/nginx restart
每月1、 10、22日的4 : 45重启nginx。

10 1 * * 6,0 /etc/init.d/nginx restart
每周六、周日的1 : 10重启nginx。

0,30 18-23 * * * /etc/init.d/nginx restart
每天18 : 00至23 : 00之间每隔30分钟重启nginx。

0 23 * * 6 /etc/init.d/nginx restart
每星期六的11 : 00 pm重启nginx。

* */1 * * * /etc/init.d/nginx restart
每一小时重启nginx

* 23-7/1 * * * /etc/init.d/nginx restart
晚上11点到早上7点之间,每 隔一小时重启nginx

0 11 4 * mon-wed /etc/init.d/nginx restart
每月的4号与每周一到周三 的11点重启nginx

0 4 1 jan * /etc/init.d/nginx restart
一月一号的4点重启nginx

*/30 * * * * /usr/sbin/ntpdate 210.72.145.20

每半小时同步一下时间


date -s 00:59:30  //更改系统时间
yum install -y ntp
返回顶部