shell脚本命令支持任务每天定时重启

时间:2025-05-07 07:29:05
while true do #先停止上次进程(xxx:应用标识) PID=`ps -ef|grep xxx|grep -v grep|awk '{print $2}'` if [ -n "$PID" ] then kill -9 $PID fi #脚本启动当前时间 nowtime=$(date "+%Y-%m-%d %H:%M:%S") echo "脚本启动当前时间:$nowtime" #下次重启时间(明天凌晨05点30分) restarttime="$(date -d tomorrow "+%Y-%m-%d") 05:30:00" echo "脚本下次重启时间:${restarttime}s" #转为时间戳 nowtime_stamp=$(date --date="$nowtime" +%s) restarttime_stamp=$(date --date="$restarttime" +%s) #启动应用 nohup java -jar xxx.jar -Dspring.config.location=xxx/application.properties >> test.log 2>&1& #获取将要休眠的时间(秒) sleeptime=$((restarttime_stamp - nowtime_stamp)) #如果sleeptime小于或等于0 if [ $sleeptime -le 0 ] then break fi echo "休眠:${sleeptime}s" #开始等待,直至明天凌晨05点30分,开始下一次循环 sleep "${sleeptime}s" done