码迷,mamicode.com
首页 > 其他好文 > 详细

xj监控端口,模拟登陆脚本

时间:2018-05-03 16:40:10      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:int   登陆脚本   grep -v   mail -s   tool   kill   新疆   模拟   for   

#!/bin/bash

date=`date +%Y%m%d-%H%M`
count=0
ip1=124.117.246.195 
ip2=124.117.246.194
port1=(443 80 6051 22101 11194)
port2=(443 80)

for (( k=0; k<5; k++ )) ; do
    sleep 1
    for i in ${port1[@]} ; do
        nc -w 40 $ip2 -z ${i} >> /dev/null
        if [ $? != 0 ];then
            count=$(($count+1))
        fi
        if [ "$count" == "3" ]; then
            echo "$date $ip2 ${i} 异常 !!!" | mail -s "新疆正式环境异常" team_cloud_service@syberos.com
            count=0
            break
        fi
    done
done

sleep 1
count=0

for (( k=0; k<5; k++ )) ; do
    sleep 1
    for i in ${port2[@]} ; do
        nc -w 40 $ip1 -z ${i} >> /dev/null
        if [ $? != 0 ];then
            count=$(($count+1))
        fi
        if [ "$count" == "3" ]; then
            echo "$date $ip1 ${i} 异常 !!!" | mail -s "新疆正式环境异常" team_cloud_service@syberos.com
            echo send mail
            count=0
            break
        fi
    done    
done

sleep 1
count=0

for (( k=0; k<5; k++ )) ; do
    sleep 2
    ps aux | grep multimech-run | grep -v grep | awk {print $2} | xargs kill -9
    cd /usr/local/src/python-scripts/pmtool
    multimech-run my_send_login > /usr/local/src/scripts/xinjiang.txt
    sed -i 20,$d /usr/local/src/scripts/xinjiang.txt
    diff /usr/local/src/scripts/xinjiang.txt /usr/local/src/scripts/xinjiang_ok.txt > /dev/null
    if [ $? != 0 ];then
        count=$(($count+1))
    fi
    if [ "$count" == "3" ]; then
            multimech-run my_send_login > /usr/local/src/scripts/xinjiang.txt
            cat /usr/local/src/scripts/xinjiang.txt | mail -s "新疆正式环境异常" team_cloud_service@syberos.com
            count=0
            break
    fi
done

xj监控端口,模拟登陆脚本

标签:int   登陆脚本   grep -v   mail -s   tool   kill   新疆   模拟   for   

原文地址:https://www.cnblogs.com/wangmo/p/8985659.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!