首页 运维 Linux 查看内容

Linux定时任务:监测某个进程是否存在,不存在就拉起该进程

2021-7-31 23:39 1658 0

摘要: Linux定时任务:监测某个进程是否存在,不存在就拉起该进程。一、进程监测脚本root@wk:~# vi /usr/bin/test.sh #!/bin/sh source /etc/profile process=`ps |grep /usr/bin/deviceManagement|grep -v grep` if ; the ...
关键词: deviceManagement usr bin grep test sleep echo PING 进程 process

Linux定时任务:监测某个进程是否存在,不存在就拉起该进程。

一、进程监测脚本

root@wk:~# vi /usr/bin/test.sh 
#!/bin/sh
source /etc/profile
process=`ps |grep /usr/bin/deviceManagement|grep -v grep`
if [ "$process" == "" ]; then #deviceManagement not exist
        echo "deviceManagement process not exist..."
        IP=`cat /usr/bin/config.ini | grep host | awk -F '=' '{print $2}'|sed 's/\"//g'`
        echo "ip:"${IP}
        PING=`ping -c 5 ${IP} | grep -v grep|grep '64 bytes' |wc -l`
        echo "ping:"${PING}
        if [ ${PING} -ne 0 ];then
      				echo "start deviceManagement..."
              /usr/bin/deviceManagement >> /root/deviceMana.log 2>&1 &
        else
      				echo "server ip unreachable..."
        fi
fi

二、添加定时任务,每隔10秒检测一次

root@wk:~# crontab -e
* * * * * sleep 10; /usr/bin/test.sh
* * * * * sleep 20; /usr/bin/test.sh
* * * * * sleep 30; /usr/bin/test.sh
* * * * * sleep 40; /usr/bin/test.sh
* * * * * sleep 50; /usr/bin/test.sh
*/30 * * * * /usr/sbin/fota_upgrade.sh
44 23 31 05 * lua /usr/share/netmgr/apps/auto_closewifi.lua

注:本应用需连接的服务器配置

root@wk:~# vi /usr/bin/config.ini 
host          = "192.168.2.13:1878"
userName = "admin"
password  = "admin"

本文出处: https://www.toutiao.com/a6990549769881993760/
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部