Linux看門狗指令碼 1.4

來源:互聯網
上載者:User

標籤:檔案   art   for   linux   re   c   

最近項目的看門狗經曆了三個版本。

第一個版本:

用ps -ef,如果程式掛了就啟動


第二個版本:

程式由於運行時會出現不再監聽7901連接埠,所以不能簡單判斷機器是不是掛了,而是判斷此連接埠是否有監聽


第三個版本:

當7901連接埠不再監聽,就先把原來的killall在啟動,每次輸出到檔案的內容都加日期,要不然根本不知道這事情啥時候發生的

#!/bin/shset +xsource env.shPRMGRAM=scp_platformFILE_NAME=scp_monitor.logCurrent_Time=`date +"%Y-%m-%d %H:%M:%S.%N"`echo "[${Current_Time}] monitor start...." echo "[${Current_Time}] monitor start...." >> ${WORK_DIR}/log/${FILE_NAME}port=7905TCPListeningnum=`netstat -an | grep ":$port " | awk '$1 == "tcp" && $NF == "LISTEN" {print $0}' | wc -l`if [ $TCPListeningnum = 1 ]then{    echo "[${Current_Time}] The $port is listening"}else{    echo "[${Current_Time}] The port is not listening"}fiwhile [ 1 ]do  Current_Time=`date +"%Y-%m-%d %H:%M:%S.%N"`TCPListeningnum=`netstat -an | grep ":$port " |   awk '$1 == "tcp" && $NF == "LISTEN" {print $0}' | wc -l`if [ $TCPListeningnum = 1 ]then{    echo "[${Current_Time}] The ${port} is listening" >> ${WORK_DIR}/log/${FILE_NAME}}else{    echo "[${Current_Time}] The  ${port} is not listening" >> ${WORK_DIR}/log/${FILE_NAME}    echo "[${Current_Time}] killall  scp_platform now !" >> ${WORK_DIR}/log/${FILE_NAME}    kscp      echo "[${Current_Time}] check ${PRMGRAM} quit, now restart ${PRMGRAM} ..." >> ${WORK_DIR}/log/${FILE_NAME}      scp_platform&}fi    sleep 180done



其中依賴的env.sh主要是設定環境變數和自訂的變數

#bin/bashexport ROOT=/root/scpexport WORK_DIR=${ROOT}export INCLUDE=${ROOT}/includeexport OTL=${INCLUDE}/otl_mysqlexport LD_LIBRARY_PATH=${ROOT}/lib:/usr/local/libexport ACE_ROOT=${INCLUDE}export ODBCINI=/usr/local/etc/odbc.iniexport ODBCSYSINI=/usr/local/etcPATH=${PATH}:${ROOT}/binexport PATHodbcinst -jalias wk='cd ${ROOT}'alias bin='cd ${ROOT}/bin'alias cfg='cd ${ROOT}/conf'alias rmlog='rm -rf ${ROOT}/bin/log*.*; rm -rf ${ROOT}/log/*.*'alias lis='netstat -an|grep -i 7905'alias scp='${ROOT}/bin/scp_platform &'alias moni='${ROOT}/bin/monitor.sh &'alias myps='ps -fu root|grep -v grep|grep -i scp'alias mymoni='ps -fu root|grep -v grep|grep -i moni'alias kscp='killall -9 scp_platform'alias kmoni='killall -9 monitor.sh'isqlalias mynet='netstat -an | grep 7905'ulimit -c unlimitedulimit -n 65530





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.