定时监控任务

工作 · 2023-06-28

创建脚本

#!/bin/sh
pid=0
proc_num() 
{
    num=`ps -ef | grep 项目名称 | grep -v grep | wc -l` 
    return $num 
}
proc_id()
{  
    pid=`ps -ef | grep 项目名称 | grep -v grep | awk '{print $2}'` 
} 
proc_num  #获取进程数
number=$?  #获取返回值
if [ $number -eq 0 ]  #没有该进程,则重启
then
    sh 启动脚本.sh  # 重启程序
    proc_id
   echo "重启服务" >> watch-server.log 
else
   echo "服务正常"
fi
运维 linux
Theme Jasmine by Kent Liao