#!bin/bash
while :
do
if [ $(ps -ef | grep "JJFleetyGateway"| grep -v "grep" | wc -l) -eq 1 ];then
kill $(ps -ef|grep "JJFleetyGateway"| grep -v "grep"|awk '{print $2}')
echo "kill"
sh server.sh start
echo "restart"
else
echo "not found"
fi
sleep 2
done
bash
說明:線程
1.sh腳本聲明rest
#!bin/bashserver
2.循環結構體進程
while :
doawk
done循環
3.經過關鍵字查找進程數量grep
ps -ef | grep "JJFleetyGateway"| grep -v "grep" | wc -l腳本
4.等於符號while
-eq
5.經過關鍵字查找進程號
ps -ef|grep "JJFleetyGateway"| grep -v "grep"|awk '{print $2}'
6.線程睡眠2秒
sleep 2
7. if then else if 結構體