Linux watchdog script 1.4

Source: Internet
Author: User

The watchdog of the recent project has undergone three versions.

First version:

With PS-EF, if the program hangs, it starts.


A second version:

program because the runtime will not listen to the 7901 port, so it is not easy to determine whether the machine is hanging, but to determine if this port is listening


A third version:

When the 7901 port is no longer listening, the original killall in the start, each output to the content of the file to add the date, or do not know when this thing happened

#!/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 ' $ = = ' TCP ' && $NF = = ' LISTEN ' {print $} ' |  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 ' $ = = ' TCP ' && $NF = = ' LISTEN ' {print $} ' | Wc-l ' if [$TCPListeningnum = 1]then{echo "[${current_time}] The ${port} is listening" >> ${work_dir}/log/${fil e_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



The main env.sh that depend on are setting environment variables and custom variables

#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 Mon I ' Alias kscp= ' killall-9 scp_platform ' Alias kmoni= ' killall-9 monitor.sh ' isqlalias mynet= ' Netstat-an | grep 7905 ' ulimit-c unlimitedulimit-n 65530





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.