Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: arpadszasz/mhping
base: be8e8894d8
...
head fork: arpadszasz/mhping
compare: bf9cb7b75d
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 24 additions and 9 deletions.
  1. +5 −1 README.pod
  2. +19 −8 bin/mhping
View
6 README.pod
@@ -8,13 +8,17 @@ mhping - Multiple host ping
=head1 SYNOPSIS
- perl mhping
+ perl mhping hosts.cfg
=head1 DESCRIPTION
mhping is a sysadmin tool that allows You to simultaneously check multiple hosts
for availability.
+=head1 HOSTS LIST
+
+Hosts must be provided one per line in a plain text file.
+
=head1 BUGS
Please report bugs on github: L<https://github.com/arpadszasz/mhping/issues>
View
27 bin/mhping
@@ -13,9 +13,8 @@ $|++;
my $VERSION = 0.001001;
-my @hosts = qw(
- localhost
-);
+my $hosts_file = $ARGV[0] or die "No hosts file specified!\n";
+my @hosts = parse_hosts($hosts_file);
my @workers;
foreach my $host (@hosts) {
@@ -27,6 +26,18 @@ threads->create( 'show_report', \@workers )->join;
exit 0;
+sub parse_hosts {
+ my $hosts_file = shift;
+ open( my $hosts_fh, '<', $hosts_file )
+ or die "Can't open file hosts file '$hosts_file'!\n";
+ my @hosts;
+ while (<$hosts_fh>) {
+ chomp;
+ push( @hosts, $_ );
+ }
+ return @hosts;
+}
+
sub show_report {
my $workers = shift;
@@ -34,18 +45,18 @@ sub show_report {
while (1) {
print $tty_clear;
- printf "%4s %-30s %10s \n", 'TID', 'Host', 'RTT';
+ printf "%2s %-30s %10s \n", '#', 'Host', 'RTT';
print '-' x 46, "\n";
+ my $worker_count;
foreach my $worker ( @{$workers} ) {
my $message;
if ( $worker->{thread}->is_running ) {
$message = $worker->{queue}->dequeue;
-
next unless $message;
-
- printf "[%2d] %-30s %10s \n",
- $worker->{thread}->tid, $worker->{host}, $message;
+ $worker_count++;
+ printf "%2d %-30s %10s \n",
+ $worker_count, $worker->{host}, $message;
}
}

No commit comments for this range

Something went wrong with that request. Please try again.