簡(jiǎn)潔版:
#! /bin/bash # author caoxin # time 2012-10-10 # program : 判斷進(jìn)行是否存在,并重新啟動(dòng) function check(){ count=`ps -ef |grep $1 |grep -v "grep" |wc -l` #echo $count if [ 0 == $count ];then nohup python /runscript/working/$1 fi } check behaviors.py
詳細(xì)版:
#!/bin/bash # #調(diào)用關(guān)閉jboss進(jìn)程腳本 stopMethodServer.sh #打印出當(dāng)前的jboss進(jìn)程:grep jboss查詢(xún)的jboss進(jìn)程,grep -v "grep" 去掉grep進(jìn)程 jmsThread=`ps -ef | grep gdms | grep jboss | grep -v "grep"` echo $jmsThread #查詢(xún)jboss進(jìn)程個(gè)數(shù):wc -l 返回行數(shù) count=`ps -ef | grep gdms | grep jboss | grep -v "grep" | wc -l` echo $count sec=7 #開(kāi)始一個(gè)循環(huán),以判斷進(jìn)程是否關(guān)閉 for var in 1 2 do if [ $count -gt 0 ]; then #若進(jìn)程還未關(guān)閉,則腳本sleep幾秒 echo sleep $sec second the $var time, the JMS thread is still alive sleep $sec else #若進(jìn)程已經(jīng)關(guān)閉,則跳出循環(huán) echo "break" break fi done #if [ $count -eq 0 ]; then # echo "nohup startMethodServer.sh " # nohup startMethodServer.sh #else # echo "It's better to check the thread!!!" #fi #調(diào)用啟動(dòng)腳本 nohup startMethodServer.sh
標(biāo)簽:朝陽(yáng) 隨州 延邊 青島 雅安 通遼 西藏 南充
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Shell實(shí)現(xiàn)判斷進(jìn)程是否存在并重新啟動(dòng)腳本分享》,本文關(guān)鍵詞 Shell,實(shí)現(xiàn),判斷,進(jìn)程,是否,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。