#!/bin/bash
. /etc/init.d/functions #引入函数库
check_count=0
# 定义检测
function wait(){
echo -n '3秒后,执行检查URL操作.';
for ((i=0;i<3;i++))
do
echo -n "."; sleep 1
done
echo
}
function check_url(){
LOG_FILE="autostart.log"
#检测nginx
curtime=$(date "+%Y-%m-%d %H:%M:%S")
pnginx=`ps -ef |grep dmserver | grep -v "grep" | wc -l`
if [ $pnginx -eq 0 ]; then
echo "$curtime 系统检测到dmserver已挂掉,启动中...." >> autostart.log;
/etc/init.d/DmServiceDMSERVER restart #启动nginx命令
echo "$curtime DMSERVER启动完成" >> autostart.log;
else
echo "$curtime 系统检测到DMSERVER运行正常" >> autostart.log;
fi
((check_count++)) #<==检测次数+1
}
main(){ #<==定义主函数
while true #<==开启一个持续循环
do
check_url #<==加载检测url的函数
echo "--------------check count:${check_count}-------------------"
sleep 10 #<==间歇10秒
done
}
main #<==调用主函数运行程序