-#!/usr/bin/perl
+#!/usr/bin/env perl
=pod
-broadcastA|ddr <ip>: Broadcast IP (Default: Current subnet)
-broadcastT|ime <seconds>: Number of sends to wait for responses to broadcast
- (Default: 30 seconds)
+ (Default: 10 seconds)
=head1 DESCRIPTION
use Clearadm;
use Display;
+use OSDep;
use Utils;
my $VERSION = '$Revision: 1.1 $';
my $broadcastTime = 10;
-sub discover ($) {
+sub discover($) {
my ($broadcast) = @_;
my $startTime = time;
verbose "Performing discovery (for $broadcastTime seconds)...";
while (<$broadcast>) {
- if (/from (.*):/) {
- my $ip = $1;
- my $hostname = gethostbyaddr (inet_aton ($ip), AF_INET);
-
- unless ($hosts{$ip}) {
- verbose "Received response from ($ip): $hostname";
- $hosts{$ip} = $hostname;
- } # unless
+ display "Received line: $_";
+ if (/from (\S+) \((.+)\)/) {
+ my $hostname = $1;
+ my $ip = $2;
+
+ # Remove domain
+ $hostname =~ s/(\w+)\..*/$1/;
+
+ unless ($hosts{$ip}) {
+ verbose "Received response from ($ip): $hostname";
+ $hosts{$ip} = $hostname;
+ } # unless
} # if
- last
- if (time () - $startTime) > $broadcastTime;
+ last if (time() - $startTime) > $broadcastTime;
} # while
verbose "$broadcastTime seconds has elapsed - discovery complete";
} # discover
# Main
-my $broadcastAddress = inet_ntoa (INADDR_BROADCAST);
+my $broadcastAddress = inet_ntoa(INADDR_BROADCAST);
-GetOptions (
+GetOptions(
usage => sub { Usage },
verbose => sub { set_verbose },
debug => sub { set_debug },
'broadcastAddr=s' => \$broadcastAddress,
) or Usage "Invalid parameter";
-Usage 'Extraneous options: ' . join ' ', @ARGV
- if @ARGV;
+Usage 'Extraneous options: ' . join ' ', @ARGV if @ARGV;
# Announce ourselves
verbose "$FindBin::Script V$VERSION";
-my $broadcastCmd = "ping -b $broadcastAddress 2>&1";
+my $broadcastCmd = 'ping ';
+if ($ARCHITECTURE eq 'solaris') {
+ $broadcastCmd .= '-s ';
+} else {
+ $broadcastCmd .= '-b ';
+} # if
+
+$broadcastCmd .= "$broadcastAddress 2>&1";
+
my $pid = open my $broadcast, '-|', $broadcastCmd
or error "Unable to do $broadcastCmd", 1;
verbose_nolf 's' if $nbrHosts != 1;
verbose " on subnet $broadcastAddress";
-foreach (sort values %hosts) {
- my $verbose = get_verbose () ? '-verbose' : '';
+for (sort values %hosts) {
+ my $verbose = get_verbose() ? '-verbose' : '';
my ($status, @output) = Execute "updatesystem.pl -host $_ $verbose";
- error "Unable to update host $_ (Status: $status)\n"
- . join ("\n", @output), 1
- if $status;
+ error "Unable to update host $_ (Status: $status)\n" . join ("\n", @output), 1 if $status;
verbose join "\n", @output;
-} # foreach
+} # for
=pod
=begin html
<blockquote>
-<a href="http://clearscm.com/php/cvs_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
-<a href="http://clearscm.com/php/cvs_man.php?file=lib/Display.pm">Display</a><br>
-<a href="http://clearscm.com/php/cvs_man.php?file=lib/Utils.pm">Utils</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
</blockquote>
=end html
Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
-=cut
\ No newline at end of file
+=cut