本文共 1647 字,大约阅读时间需要 5 分钟。
port=$1if [ ! -n "$port" ];then echo "please enter the args port!" exitfiservice_name=$2nc -w2 localhost $portif [ $? != 0 ];then echo '【'`date +"%Y-%m-%d %H:%M:%S"`'】检测到端口【'${port}'】已经关闭,该服务重新启动'>>/root/monitor_log.log sh $2 exitfi
crontab -e* * * * * sleep 10; /root/port_monitor.sh 90 /var/dbstar/program/dmail-tomcat/bin/startup.sh
vim /etc/mail.rc在最后添加以下两行代码
set from=xxx@xxx.com.cn smtp=mail.xxx.com.cnset smtp-auth-user=xxx@xxx.com.cn smtp-auth-password=123456 smtp-auth=login发送邮件命令,添加到第14行(shell)
echo "the port ${port} is down,the server is restart ${port} port!!"|mail -s "port ${port}/${service_name} is down!" xxx@xxx.com.cn
在catalina.sh中添加如下代码即可
JAVA_OPTS="-Dfile.encoding=utf-8"
最终代码(shell)
port=$1if [ ! -n "$port" ];then echo "please enter the args port!" exitfiservice_name=$2nc -w2 localhost $portif [ $? != 0 ];then echo '【'`date +"%Y-%m-%d %H:%M:%S"`'】检测到端口【'${port}'】已经关闭,该服务重新启动'>>/root/monitor_log.log if [ -n "$service_name" ];then sh $2 fi if [ ! -n "$service_name" ];then mkdir /tmp/portmonitor/ -p touch /tmp/portmonitor/${port}.log flag=$(cat /tmp/portmonitor/${port}.log) if [ ! -n "$flag" ] || [ "1" != "$flag" ];then echo '1'>/tmp/portmonitor/${port}.log fi fi echo "the port ${port} is down,the server is restart ${port} port!!"|mail -s "port ${port}/${service_name} is down!" xxx@xxx.com.cn exitfi
转载地址:http://ainni.baihongyu.com/