守護進程的shell--tipserver 1:可以直接關掉終端,在後台運行2:可以查詢服務的狀態 3:可以定時啟動需要啟動並執行程式(範例為17點啟動) 4:可以在運行時避免重複啟動tipserver #!/bin/sh run_main_programer(){while truedoif [ "$date_hour" = '17' ]thenas=`date +'%Y%m%d_%H%M%S'`sh ./control_sh.sh >log/control_sh_$as.logsleep 3600fisleep 300date_hour=`date +'%H'`done} myself=`echo $0 | sed 's/^\.\///g'` if [ $# -eq 0 ]then echo "Unknown command option" echo "Usage::" echo " $myself start | stop | status" exitfi case "x$1"inxstart)#當前後台啟動並執行線程列表thread=`ps -ef | grep -v grep | grep -w "$myself" | grep "start" | awk '{ print $2 }'`#只有本線程運行if [ "$thread" = "$$" ]thennohup sh $myself start >/dev/null &sleep 3echo "The $myself have been started."else#取得父線程號father_thread=`ps -ef | grep -v grep | grep "$myself" | grep "start" | grep "$$" | awk '{ print $3 }'`#當前線程的父線程存在if [ `ps -ef | grep -v grep | grep "$myself" | grep "start" | grep "$father_thread" | wc -l` -eq 2 ]thenrun_main_programerfiecho "The $myself is running."fi;;xstop)thread=`ps -ef | grep -v grep | grep "$myself" | grep "start" | awk '{ print $2 }'`if [ -n "$thread" ]thenkill -9 ${thread} 2>/dev/nullfiecho "The $myself have been stoped.";;xstatus)thread=`ps -ef | grep -v grep | grep "$myself" | grep "start" | awk '{ print $2 }'`if [ -n "$thread" ]thenecho "The $myself is running."elseecho "The $myself is not running."fi;;*)echo ' Error parameter.'esac