From d5ab841ee87546690ae30ad04dc32b8b014a2978 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 1 Jun 2011 23:55:13 +0200 Subject: beep simulation --- bin/ekgping | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'bin/ekgping') diff --git a/bin/ekgping b/bin/ekgping index ec43040..1487b72 100755 --- a/bin/ekgping +++ b/bin/ekgping @@ -13,8 +13,11 @@ our $VERSION = '0.1'; my $host = shift; my $id = 0; my $last_id = 0; +my $is_beep = 1; +my $was_beep = 1; +my $no_reply = 0; -my $harness = harness(['ping', '-n', $host], +my $ping = harness(['ping', '-n', $host], '<' => \undef, '>&' => \&parse_ping_output, ); @@ -29,27 +32,41 @@ sub parse_ping_output { } } -$harness->start(); +$ping->start(); + +sleep(2); # Ignore first line -$harness->pump(); +$ping->pump(); while(usleep(100_000)) { - $harness->pump_nb(); + $ping->pump_nb(); if ($id != $last_id) { + $is_beep = 1; print '^'; $last_id = $id; + $no_reply = 0; } else { + $is_beep = 0; + $no_reply++; + if ($no_reply > 15) { + $is_beep = 1; + } + print '_'; } + if ($is_beep) { + print 'O'; + } + STDOUT->flush(); } -$harness->kill_kill( grace => 1 ); +$ping->kill_kill( grace => 1 ); __END__ -- cgit v1.2.3