Shell實(shí)現(xiàn)判斷進(jìn)程是否存在并重新啟動(dòng)腳本分享
更新時(shí)間:2014年09月28日 10:14:40 投稿:junjie
這篇文章主要介紹了Shell實(shí)現(xiàn)判斷進(jìn)程是否存在并重新啟動(dòng)腳本分享,本文給出了兩個(gè)實(shí)現(xiàn)腳本,分簡潔版和詳細(xì)版,需要的朋友可以參考下
簡潔版:
#! /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查詢的jboss進(jìn)程,grep -v "grep" 去掉grep進(jìn)程 jmsThread=`ps -ef | grep gdms | grep jboss | grep -v "grep"` echo $jmsThread #查詢jboss進(jìn)程個(gè)數(shù):wc -l 返回行數(shù) count=`ps -ef | grep gdms | grep jboss | grep -v "grep" | wc -l` echo $count sec=7 #開始一個(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 &
相關(guān)文章
輸出執(zhí)行操作和打印日志的shell腳本實(shí)例
下面小編就為大家?guī)硪黄敵鰣?zhí)行操作和打印日志的shell腳本實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03Shell腳本實(shí)現(xiàn)監(jiān)測文件變化的示例詳解
這篇文章主要和大家分享一個(gè)Shell腳本,可以實(shí)現(xiàn)監(jiān)測文件變化功能。文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-06-06Shell編程之Shell變量學(xué)習(xí)總結(jié)
這篇文章主要介紹了Shell腳本編程中Shell變量的學(xué)習(xí)總結(jié),需要的朋友可以參考下2014-03-03