summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-06-02 12:26:50 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-06-02 12:28:57 +0200
commit18e96317f24f8240857101999e2c3a4f8c5a9c37 (patch)
treea6c79e09656abbaf2888b49376bac62a73b1489f /bin
parentd5ab841ee87546690ae30ad04dc32b8b014a2978 (diff)
Minor cleanup
Diffstat (limited to 'bin')
-rwxr-xr-xbin/ekgping45
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();
}