#!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说明:
1.sh脚本声明
#!bin/bash
2.循环结构体
while :
dodone
3.通过关键字查找进程数量
ps -ef | grep "JJFleetyGateway"| grep -v "grep" | wc -l
4.等于符号
-eq
5.通过关键字查找进程号
ps -ef|grep "JJFleetyGateway"| grep -v "grep"|awk '{print $2}'
6.线程睡眠2秒
sleep 2
7. if then else if 结构体