目录
crontab定时任务方法
1、确保crond服务正常运行
2、crond服务相关命令
3、编辑crond定时任务
编写自动重启脚本
1、定时重启脚本
2、设置开机启动
3、重启系统之后,自动重启进程会启动
crontab定时任务方法
1、确保crond服务正常运行#查看crond服务状态[[emailprotected]~]#servicecrondstatus
crond(pid2265)isrunning...
2、crond服务相关命令#停止crond服务[[emailprotected]~]#servicecrondstop
Stoppingcrond:[OK]
#启动crond服务
[[emailprotected]~]#servicecrondstart
Startingcrond:[OK]
#重启crond服务
[[emailprotected]~]#servicecrondrestart
Stoppingcrond:[OK]
Startingcrond:[OK]
#重新加载crond配置
[[emailprotected]~]#servicecrondreload
Reloadingcrond:[OK]
[[emailprotected]~]#
3、编辑crond定时任务#编辑定时任务内容
[[emailprotected]~]#crontab-e
crontab定时任务详解
编写自动重启脚本
1、定时重启脚本#!/bin/bash
T=1214#重启时间
while(true)
do
sleep59
time=$(date"+%H%M")
if[$time==$T];then
#重启程序命令
reboot
else
echodoNothing
fi
done
2、设置开机启动[[emailprotected]~]#vim/etc/rc.local
#在最后添加一行
/root/restart.sh&
3、重启系统之后,自动重启进程会启动