Arm Linux Shellは、シェルを学習してコマンド出力を取得し、テスト変数wget T3に配置します。タイムアウトは3秒で、t1は1回だけ試行され、2>&1を追加する必要があります。それ以外の場合、テストポートは使用できません。定期的に再起動+シングルインスタンスガード

#!/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  

 

おすすめ

転載: blog.csdn.net/chenhao0568/article/details/108362236