原!linux 监控 jar定时任务 挂了重启 脚本

#!/bin/bash

time=$(date "+%Y-%m-%d %H:%M:%S")
echo "monitor start at: ${time}"

PATH=/apprun/jdk/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

statistics_num=`ps -ef|grep open-task-1.0-SNAPSHOT.jar |grep -v grep |wc -l`

if [[ "$statistics_num" -eq 0 ]]; then
        
      echo "[***ERROR***] task exceptional stop, begin to restart....."
      cd /apprun/task
      ./taskstart.sh
      echo "restart ok"

else 
    echo "task running normally"

fi

time=$(date "+%Y-%m-%d %H:%M:%S")
echo -e  "monitor end at: ${time} \n\n"

1.创建task_monitor.sh 脚本,写入以上内容

2.crontab -e  ,写入以下脚本 

*/2 * * * * /apprun/task/task_monitor.sh >> /apprun/task/task_monitor.log

(每2分钟执行一次,日志放入该目录下的task_monitor.log)

转载于:https://www.cnblogs.com/wuyun-blog/p/9673768.html

你可能感兴趣的:(原!linux 监控 jar定时任务 挂了重启 脚本)