1、编写自动重启脚本
#!/bin/sh
#接口重启命令
cd /home/service
# 查询程序占用
project=`ps -ef|grep test-V1.0.jar|grep -v grep|wc -l`
date=`date`
server_name="test-V1.0"
# $? -ne 0 不存在
# $? -eq 0存在
if [ $project -eq 0 ]
then
echo "时间:${date},${server_name}服务器已挂,重启中..."
nohup java -jar /home/service/test-V1.0.jar --${date} >/dev/null 2>&1 &
echo `date +%Y-%m-%d` `date +%H:%M:%S` $server_name >> /home/service/restart/logs/restart.log
echo "时间:${date},重启完成!"
fi
2、进行转码
vim test.sh
:set ff=unix
:wq!
需要赋予该sh文件可执行权限
chmod a+x test.sh
3、
编辑系统定时任务文件
crontab -e
4、使用cron表达式,设置1分钟运行一次
*/1 * * * * bash /opt/restart/test.sh >> /opt/restart/cron/log.log
例如:*/1 * * * * bash /opt/restart/pay.sh >> /opt/restart/cron/restart.log
5、查看定时任务日志,可以看到每隔1分钟执行了一次
tail -f /var/log/cron