Unable to compare ping times on fly

前端 未结 3 1135
不知归路
不知归路 2021-01-28 00:22

I tried the following command unsuccessfully

sdiff <(ping www.nato.int) <(ping www.reuters.com)

Is there any way to have a real-t

3条回答
  •  一整个雨季
    2021-01-28 01:17

    Usually I just open two xterms side-by-side and run ping in each. Or in one terminal "ping host1 & ping host2&"

    fping -e will give you the latency to a list of hosts in one run. So you can just do: watch fping -e www.google.com www.yahoo.com www.kernel.org

    Not everyone has watch, but you can just do this (and then you can see the history): while :; do date; fping -e www.google.com www.yahoo.com www.kernel.org; sleep 1; done

    The output is still ugly, and not everyone has fping installed either..

    Here's a start if you want to produce decent looking output. Just give it a list of hosts as arguments.

    #!/usr/bin/perl
    use strict;
    use warnings;
    use POSIX;
    
    for(;;) {
        print strftime("%T:", localtime);
        foreach my $host (@ARGV) {
            my $a=`ping -c 1 $host`;
            my $latency;
            if($a =~ /rtt.* =\s+([\d.]+)\//s) {
                $latency=$1;
            } else {
                $latency="(dropped)";
            }
            print "$host:$latency\t";
        }
        print "\n";
        sleep(1);
    }
    

提交回复
热议问题