项目背景
在一些项目场景中需要定时重启某些程序段,来保障程序的正常运行,为此我们可以不写shell脚本对程序进行控制,例如要对xpublish的ipage段进行重启,要用到的命令是
systemctl stop hik.xpublish.xpublish-ipag.1 systemctl start hik.xpublish.xpublish-ipag.1
可以写到shell文件里
#! /bin/bash
systemctl stop hik.xpublish.xpublish-ipag.1
systemctl start hik.xpublish.xpublish-ipag.1
TIME=`date +%Y%m%d%H%M%S`
LOG=${TIME}-"restart ipage"
echo ${LOG} >> /home/hik/task/tasklog.txt
添加脚本定时启动计划,使用命令crontab -e
添加定时任务执行,使用Scheduled表达式
2 * * * * /home/hik/task/task.sh
查看日志就能看到每个小时的02分就会执行一次脚本