1. 程式人生 > >檢測端口並進行下一步

檢測端口並進行下一步

腳本

腳本功能:檢測8080和8081端口是否在運行,如果沒在運行,則/opt/tomcat-background/bin/startup.sh



vi /root/aa.sh

#!/bin/bash

i1=`nmap -sS 127.0.0.1 -p 8080 | grep $8080 | awk ‘{printf $2}‘`

i2=`nmap -sS 127.0.0.1 -p 8081 | grep $8081 | awk ‘{printf $2}‘`

if [ "$i1" == "closed" ]; then

/opt/tomcat-background/bin/startup.sh

fi

if [ "$i2" == "closed" ]; then

/opt/tomcat-zjq-front/bin/startup.sh

fi


每五分鐘檢測一次

crontab -e

*/5 * * * * sh /root/aa.sh

檢測端口並進行下一步