diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-06-02 12:26:50 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-06-02 12:28:57 +0200 |
commit | 18e96317f24f8240857101999e2c3a4f8c5a9c37 (patch) | |
tree | a6c79e09656abbaf2888b49376bac62a73b1489f /bin | |
parent | d5ab841ee87546690ae30ad04dc32b8b014a2978 (diff) |
Minor cleanup
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/ekgping | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/bin/ekgping b/bin/ekgping index 1487b72..65b066f 100755 --- a/bin/ekgping +++ b/bin/ekgping @@ -10,14 +10,15 @@ use Time::HiRes qw(usleep); our $VERSION = '0.1'; -my $host = shift; -my $id = 0; +my $host = shift; +my $id = 0; my $last_id = 0; -my $is_beep = 1; -my $was_beep = 1; -my $no_reply = 0; +my $beep; +my $was_beep = 1; +my $dead_count = 0; -my $ping = harness(['ping', '-n', $host], +my $ping = harness( + [ 'ping', '-n', $host ], '<' => \undef, '>&' => \&parse_ping_output, ); @@ -27,42 +28,40 @@ sub parse_ping_output { chomp($line); - if ($line =~ m{ ^ \d+ \s bytes \s from \s \S+ \s icmp_req = (?<id> \d+ ) }x) { + if ( $line + =~ m{ ^ \d+ \s bytes \s from \s \S+ \s icmp_req = (?<id> \d+ ) }x ) + { $id = $+{id}; } + + return; } $ping->start(); -sleep(2); - # Ignore first line $ping->pump(); -while(usleep(100_000)) { +while ( usleep(100_000) ) { $ping->pump_nb(); - if ($id != $last_id) { - $is_beep = 1; - print '^'; - $last_id = $id; - $no_reply = 0; + if ( $id != $last_id ) { + $beep = 1; + print q{^}; + $last_id = $id; + $dead_count = 0; } else { - $is_beep = 0; - $no_reply++; - if ($no_reply > 15) { - $is_beep = 1; + $beep = 0; + $dead_count++; + if ( $dead_count > 30 ) { + $beep = 1; } print '_'; } - if ($is_beep) { - print 'O'; - } - STDOUT->flush(); } |