Shell script to monitor whether the online service port normally open

Preface:

  Online services normally available is crucial when a port service is running abnormally stopped, we expect the timing script can be started automatically, and then people do not need to start having problems.

  For example: listening Mysql service is normal, we are usually thinking way of checking whether the 3306 port has started to listen.

method:

To Mysql service, port 3306, for example, shell scripts written as:

! # / bin / bash 
# Mysql monitoring service is turned on 
 
Port = `netstat -nlt | grep  3306 | WC - l`
 IF [$ Port -ne 1 ]
 the then 
 /etc/init.d/ mysqld Start
 the else 
 echo  " MySQL IS running " 
fi

To webSocket service, port 8820, for example, shell scripts written as:

! # / bin / bash 
# webSocket monitoring service is turned on 
 
Port = `netstat -nlt | grep  8820 | WC - l`
 IF [$ Port -ne 1 ]
 the then 
  $ (cd / Home / Start start.php the WebSocket && PHP - d )
 the else 
 echo  " the WebSocket IS running " 
fi

 

Guess you like

Origin www.cnblogs.com/wenzheshen/p/12667033.html