#!bin/bash
while :
do
processNum='ps -ef | grep "test2" | grep -v "grep" | wc -l'
if [ ${processNum} -eq 1 ];then
killall test2.sh
./test2.sh
else
echo "not found"
fi
sleep 10
while :
do
processNum='ps -ef | grep "test2" | grep -v "grep" | wc -l'
if [ ${processNum} -eq 1 ];then
killall test2.sh
./test2.sh
else
echo "not found"
fi
sleep 10
done
说明:
#!bin/bash:告诉系统该脚本需要用sh来执行
while :无限循环模式,注意while与“:”之间有一个空格!
do:与while一起
processNum='ps -ef | grep "test2" | grep -v "grep" | wc -l'
定义了一个变量processNum,
'ps -ef | grep "test2" | grep -v "grep" | wc -l'是一条执行语句,意思是返回名字为test2的程序有几个。