#!/bin/sh
while true
do
#shell获取命令输出结果放到test变量 T3超时3秒,t1只试一次 必须加2>&1 否则得不到 测试端口是否通,通则返回含有MB/s或response的子字符串
test=`wget -T3 -t1 http://127.0.0.1:10777 2>&1`
echo ${#test}
echo ${test}
#截取并删除子字符串
testdel=${test#*response}
echo ${#testdel}
echo ${testdel}
#删除后的字符串与原字符串对比,不等则存在子符串,则端口连通
if [ "${#test}" -eq "${#testdel}" ]
then
echo "============No"
else
echo "!!!!!!!!!!!!Yes,connected"
fi
sleep 2s
done
exit 0
スケジュールされた再起動+シングルインスタンスガード
#!/bin/sh
#定时每天1:30重启应用程序
killall -9 crond
mkdir -p /var/spool/cron/crontabs
#crontab -e
#30 1 * * * sh /home/agent/bin/timerrestartapp.sh
chmod -R 777 /home
cp -rf /home/agent/bin/crontabs/. /var/spool/cron
chmod -R 777 /var/spool/cron
sleep 3
crond
while true
do
#进程名字可修改
PRO_NAME=ysagentmce01
#用ps获取进程数量
NUM=`ps |grep ${PRO_NAME} |grep -v "grep" |wc -l`
#echo $NUM ${PRO_NAME}
if [ $NUM != 1 ]
then
echo "ERROR ,RESET ,NUM:" $NUM $(date)
killall -9 "${PRO_NAME}"
/home/agent/bin/ysagentmce01 &
fi
sleep 10s
done
exit 0