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"




