Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 2 files changed
  • 0 comments
  • 1 contributor

Showing 2 changed files with 24 additions and 9 deletions. Show diff stats Hide diff stats

  1. +5 1 README.pod
  2. +19 8 bin/mhping
6 README.pod
Source Rendered
@@ -8,13 +8,17 @@ mhping - Multiple host ping
8 8
9 9 =head1 SYNOPSIS
10 10
11   - perl mhping
  11 + perl mhping hosts.cfg
12 12
13 13 =head1 DESCRIPTION
14 14
15 15 mhping is a sysadmin tool that allows You to simultaneously check multiple hosts
16 16 for availability.
17 17
  18 +=head1 HOSTS LIST
  19 +
  20 +Hosts must be provided one per line in a plain text file.
  21 +
18 22 =head1 BUGS
19 23
20 24 Please report bugs on github: L<https://github.com/arpadszasz/mhping/issues>
27 bin/mhping
@@ -13,9 +13,8 @@ $|++;
13 13
14 14 my $VERSION = 0.001001;
15 15
16   -my @hosts = qw(
17   - localhost
18   -);
  16 +my $hosts_file = $ARGV[0] or die "No hosts file specified!\n";
  17 +my @hosts = parse_hosts($hosts_file);
19 18
20 19 my @workers;
21 20 foreach my $host (@hosts) {
@@ -27,6 +26,18 @@ threads->create( 'show_report', \@workers )->join;
27 26
28 27 exit 0;
29 28
  29 +sub parse_hosts {
  30 + my $hosts_file = shift;
  31 + open( my $hosts_fh, '<', $hosts_file )
  32 + or die "Can't open file hosts file '$hosts_file'!\n";
  33 + my @hosts;
  34 + while (<$hosts_fh>) {
  35 + chomp;
  36 + push( @hosts, $_ );
  37 + }
  38 + return @hosts;
  39 +}
  40 +
30 41 sub show_report {
31 42 my $workers = shift;
32 43
@@ -34,18 +45,18 @@ sub show_report {
34 45
35 46 while (1) {
36 47 print $tty_clear;
37   - printf "%4s %-30s %10s \n", 'TID', 'Host', 'RTT';
  48 + printf "%2s %-30s %10s \n", '#', 'Host', 'RTT';
38 49 print '-' x 46, "\n";
39 50
  51 + my $worker_count;
40 52 foreach my $worker ( @{$workers} ) {
41 53 my $message;
42 54 if ( $worker->{thread}->is_running ) {
43 55 $message = $worker->{queue}->dequeue;
44   -
45 56 next unless $message;
46   -
47   - printf "[%2d] %-30s %10s \n",
48   - $worker->{thread}->tid, $worker->{host}, $message;
  57 + $worker_count++;
  58 + printf "%2d %-30s %10s \n",
  59 + $worker_count, $worker->{host}, $message;
49 60 }
50 61 }
51 62

No commit comments for this range

Something went wrong with that request. Please try again.