linux 定时重启程序脚本

来源:互联网 发布:考试系统设计python 编辑:程序博客网 时间:2024/06/17 11:33
#!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

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的程序有几个。


原创粉丝点击