目录
crontab定时任务方法
1、确保crond服务正常运行
#查看crond服务状态[root@mail ~]# service crond status crond (pid 2265) is running...
2、crond服务相关命令
#停止crond服务[root@mail ~]# service crond stop Stopping crond: [ OK ] #启动crond服务 [root@mail ~]# service crond start Starting crond: [ OK ] #重启crond服务 [root@mail ~]# service crond restart Stopping crond: [ OK ] Starting crond: [ OK ] #重新加载crond配置 [root@mail ~]# service crond reload Reloading crond: [ OK ] [root@mail ~]#
3、编辑crond定时任务
#编辑定时任务内容 [root@mail ~]# crontab -e
编写自动重启脚本
1、定时重启脚本
#!/bin/bash T=1214 #重启时间 while(true) do sleep 59 time=$(date "+%H%M") if [ $time == $T ];then #重启程序命令 reboot else echo doNothing fi done
2、设置开机启动
[root@mail ~]# vim /etc/rc.local
#在最后添加一行 /root/restart.sh &