程序写好了,得监控上,嘿嘿。研究出来如下代码,进行使用,嘿嘿。 我这里每个进程只需要一个实例,即使实例有多个,也会使用不同的配置文件区分开来,否则不知道程序的哪个实例挂了, 不说了,附上代码,自己看吧。重点在config那块儿,我写的是相对目录哦。嘿嘿
#!/bin/bash #func checkProcessName # param1 threadname param2 user CheckProcess() { PROCESS_NAME="$1" if [ "$PROCESS_NAME" = "" ];then return 1; fi USER_NAME="$2" PROCESS_NUM=0 COMMAND_STR="" if [ "$USER_NAME" = "" ];then PROCESS_NUM=`ps -elf|grep "${PROCESS_NAME}" |grep -v "grep"|wc -l` else PROCESS_NUM=`ps -u "${USER_NAME}" -lf |grep "${PROCESS_NAME}" |grep -v "grep"|wc -l` fi if [ ${PROCESS_NUM} -eq 1 ];then return 0 else return 1 fi } #config process=(\ "./servers servers.ini"\ "./serverc serverc.ini"\ ) # "./baike_fspage baike_fspage.ini"\ processdir=(\ "/server/servers"\ "/server/serverc"\ ) # "/baiketrans" \ curdir=`pwd` #main while [ 1 ] ;do sleep 10 for i in $( seq 0 $[${#process[@]}-1] ) do CheckProcess "${process[$i]}" "jianghi" notLive=$? if [ $notLive -eq 1 ]; then cd ${curdir}${processdir[$i]} if [ $? -eq 0 ];then ./startup.sh echo "[" `date "+%Y/%m/%d %k:%M:%S"` "]" `pwd`/startup.sh "start..." else echo "[" `date "+%Y/%m/%d %k:%M:%S"` "] not find ${curdir}${processdir[$i]}/startup.sh " fi fi done done