zoukankan      html  css  js  c++  java
  • shell利用mysql表项的icmp检测

    作者:邓聪聪

      利用mysql的表项记录IP地址和对应状态

    +----+-----------------+--------+--------+
    | id | ip_host         | desc   | status |
    +----+-----------------+--------+--------+
    |  1 | 8.8.8.8         | 电信   |      0 |
    | 23 | 114.114.114.114 | 联通   |      0 |
    | 29 | 114.114.114.117 | 测试   |      1 |
    | 21 | 2.2.2.2         | 电信   |      1 |
    | 15 | 222.222.222.1   | 电信   |      0 |
    | 24 | 223.3.2.2       | 谷歌   |      1 |
    | 26 | 23.24.24.32     | 测完   |      1 |
    | 25 | 232.23.22.32    | 测试   |      1 |
    +----+-----------------+--------+--------+

    shell脚本内容:

    #!/bin/sh
    PATH=$PATH
    
    DB_table="iphost"
    DB_status="status"
    DB_vlues="ip_host" 
    ping_ip(){ sql_host_status
    =`mysql -uusername -ppassword test -e "select status from $DB_table where ip_host='$1'"|grep -v $DB_status` ping -c 4 -W 1 $1 > /dev/null 2>&1 if [ $? -ne $sql_host_status ] then des=`mysql -uusername -ppassword test -e "select * from iphost where $DB_vlues like '$1'"|awk '{print $3}'|grep -v desc` if [ $sql_host_status == 0 ] then #$sql_host_status="1" echo "$1 is bad" #更新状态为1 mysql -uusername -ppassword test -e "update $DB_table set $DB_status='1' where ($DB_vlues='$1')" else #$sql_host_status="0" echo "$1 is ok" #更新状态为0 mysql -uusername -ppassword test -e "update $DB_table set $DB_status='0' where ($DB_vlues='$1')" fi else continue fi } while true do echo "" while true do for i in `mysql -uusername -ppassword test -e "select ip_host from iphost" |awk '{print $1}'|grep -v ip_host` do ping_ip $i done done sleep 1 break done

      

  • 相关阅读:
    js 变量命名规范
    JS
    python 处理中文十六进制的encode %E9%99%88%E8%80%81%E5%B8%88/%E5%9B%BE%E7%89%87
    Pycharm 项目上传至Gitee/Github详细步骤
    Python 类型建议符, Python 定义函数的时候有冒号:
    Python 解析 JSON
    Python 解析 JSON
    Mac 安装 WordPress
    java常用书籍下载
    Docker环境搭建Redis4.0 Cluster
  • 原文地址:https://www.cnblogs.com/dengcongcong/p/10611391.html
Copyright © 2011-2022 走看看