From 4a649144e1f9f7ac0e02e71aa1f0a9dda2cd7e38 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 21 Jun 2011 12:36:58 +0200 Subject: Add --beep-when option (closes #1) --- Changelog | 6 ++++++ bin/ekgping | 24 ++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Changelog b/Changelog index 390d17b..927bb9f 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,9 @@ +git HEAD + + * Fix Module::Build dependency (we need >= 0.36) + * Add --beep-when option to only play beeps when the host is either dead + or alive + ekgping 1.2 - Thu Jun 16 2011 * Fix ping -n parser - it was based on a buggy(?) ping output, diff --git a/bin/ekgping b/bin/ekgping index 768cc54..e2223fa 100755 --- a/bin/ekgping +++ b/bin/ekgping @@ -5,7 +5,7 @@ use warnings; use 5.010; use File::ShareDir qw(dist_file); -use Getopt::Long; +use Getopt::Long qw(:config bundling); use IO::Handle; use IPC::Run qw(harness); use SDL::Mixer; @@ -16,6 +16,7 @@ use Time::HiRes qw(usleep); our $VERSION = '1.2'; my $beep = 0; +my $beep_when = 'both'; my $id = 0; my $rtt = 0; my $last_id = 0; @@ -29,6 +30,7 @@ my $timeout = 3; GetOptions( + 'b|beep-when=s' => \$beep_when, 'f|beep-file=s' => \$beep_file, 'q|quiet' => \$quiet, 't|timeout=f' => \$timeout, @@ -115,7 +117,11 @@ while ( usleep(100_000) ) { } if ( $id != $last_id ) { - $beep = 1; + + if ( $beep_when ~~ [qw[a alive b both]] ) { + $beep = 1; + } + if ( $rtt < 300 ) { print q{^}; } @@ -128,7 +134,9 @@ while ( usleep(100_000) ) { else { $beep = 0; $dead_count++; - if ( $dead_count > ( $timeout * 10 ) ) { + if ( $dead_count > ( $timeout * 10 ) + and $beep_when ~~ [qw[b both d dead]] ) + { $beep = 1; } @@ -157,7 +165,7 @@ B - Electrocardiograph-like visual and audible ping =head1 SYNOPSIS -B [B<-q>] [B<-t> I] [B<-f> I] I [B<--> I] +B [B<-q>] [B<-ba>|B<-bd>] [B<-t> I] [B<-f> I] I [B<--> I] =head1 VERSION @@ -185,6 +193,14 @@ interval too high, B will break. =over +=item B<-b>, B<--beep-when> B|B|B + +Only play beeps when the host is B (the short beeps) or B (the +long flatline beep). Defaults to B, meaning any beep will be played. + +You can also use the first letter of the argument, like C<< -ba >> instead of +C<< --beep-when alive >>. + =item B<-f>, B<--beep-file> I Play I instead of the default beeps. May be any sound / music file -- cgit v1.2.3