From 18e96317f24f8240857101999e2c3a4f8c5a9c37 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 2 Jun 2011 12:26:50 +0200 Subject: Minor cleanup --- bin/ekgping | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) (limited to 'bin') 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 = (? \d+ ) }x) { + if ( $line + =~ m{ ^ \d+ \s bytes \s from \s \S+ \s icmp_req = (? \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(); } -- cgit v1.2.3