Shell實現(xiàn)判斷進程是否存在并重新啟動腳本分享
更新時間:2014年09月28日 10:14:40 投稿:junjie
這篇文章主要介紹了Shell實現(xiàn)判斷進程是否存在并重新啟動腳本分享,本文給出了兩個實現(xiàn)腳本,分簡潔版和詳細版,需要的朋友可以參考下
簡潔版:
#! /bin/bash # author caoxin # time 2012-10-10 # program : 判斷進行是否存在,并重新啟動 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
詳細版:
#!/bin/bash # #調(diào)用關閉jboss進程腳本 stopMethodServer.sh #打印出當前的jboss進程:grep jboss查詢的jboss進程,grep -v "grep" 去掉grep進程 jmsThread=`ps -ef | grep gdms | grep jboss | grep -v "grep"` echo $jmsThread #查詢jboss進程個數(shù):wc -l 返回行數(shù) count=`ps -ef | grep gdms | grep jboss | grep -v "grep" | wc -l` echo $count sec=7 #開始一個循環(huán),以判斷進程是否關閉 for var in 1 2 do if [ $count -gt 0 ]; then #若進程還未關閉,則腳本sleep幾秒 echo sleep $sec second the $var time, the JMS thread is still alive sleep $sec else #若進程已經(jīng)關閉,則跳出循環(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)用啟動腳本 nohup startMethodServer.sh &
相關文章
Shell腳本實現(xiàn)監(jiān)測文件變化的示例詳解
這篇文章主要和大家分享一個Shell腳本,可以實現(xiàn)監(jiān)測文件變化功能。文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2022-06-06