thinkxen
V2EX  ›  问与答

有没有这样的一种监控程序

  •  
  •   thinkxen · Jun 12, 2014 · 3435 views
    This topic created in 4529 days ago, the information mentioned may be changed or developed.
    设定PING某一个IP,并且可以设定一个掉包的阀值,如果超过了阀值就给一份MTR出来。

    如果支持多用户管理自己的IP就更好了,呃,好吧,好像有点像监控宝了~~~
    10 replies  •  2014-06-12 20:31:54 +08:00
    msg7086
    msg7086
    Jun 12, 2014
    1
    错别字提醒:阈值

    你这种需求,写个shell脚本扔进cron跑就行了。
    Zhang
    Zhang
    Jun 12, 2014
    2
    而且是念“yu(四声)”哦!
    est
    est
    Jun 12, 2014
    3
    我想自己搞个这样的东西,无奈rawsocket需要root,不是很好用。mac下搞了半天setuid没成功。弱爆了。orz
    thinkxen
    thinkxen
    OP
    Jun 12, 2014
    4
    @msg7086
    @Zhang 多谢知道~~~念错的朋友请跟我一起念,yu值,思密达~~~
    a2z
    a2z
    Jun 12, 2014❤️1
    5
    #!/bin/bash

    timeout="100"

    if [ -z "$1" ]; then
    echo 'Please specify the host'
    exit
    fi

    while true
    do
    out=`ping $1 -c 2|tail -1|awk '{print $4}' | cut -d '/' -f 2`
    if [ "$out" == "" ] || [ "$out" > "$timeout" ]; then
    echo 'ping test failed, starting mtr...'
    mtr --report --report-cycles 5 $1 > google_net_report.txt
    fi

    echo 'ping test passed'
    done
    a2z
    a2z
    Jun 12, 2014
    6
    那啥,注意不要让别人执行,因为参数都没过滤,可以导致命令执行
    a2z
    a2z
    Jun 12, 2014
    7
    有个bug,mtr那行后面加个continue,另外似乎对比的是字符串而不是数字,也有点问题,但是大概就是这么一个意思
    thinkxen
    thinkxen
    OP
    Jun 12, 2014
    8
    @a2z 我擦,惊现SHELL小王子呀~~~
    RainFlying
    RainFlying
    Jun 12, 2014
    9
    关键是,按照你的思路,你开始 mtr 的时候可能网络就已经恢复了,
    那 mtr 又有什么意义呢?
    thinkxen
    thinkxen
    OP
    Jun 12, 2014 via Android
    10
    @RainFlying mtr秒级就可以完成,设置阈值3,在很多时侯还是很有意义的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2608 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 14:27 · PVG 22:27 · LAX 06:27 · JFK 09:27
    ♥ Do have faith in what you're doing.