#!/usr/bin/perl
##
## Multex v0.1 written 032105:1309 by Bowie J. Poag
##
## This runs a given command across several hosts,
## provided they have the main arbiter listed in
## their .rhosts file. :)
##
## Usage: multex <command>
##
## This script will only work if all the hosts you
## list in the @hosts array have an .rhosts file
## which allows connections from the system named
## in $arbiter. The command will always be invoked
## from the arbiter system, not necessarrily the
## system you're currently running it on---so make
## sure you have a copy of multex on the arbiter. :)
##
$arbiter = "grover";
startupRoutine();
execRoutine();
spinDownRoutine();
sub startupRoutine()
{
$user=`whoami`;
$whereAmI=`hostname`;
chomp($user);
chomp($whereAmI);
@hosts=(
"chapel.uconn.edu",
"fcs93934.boulder.ibm.com",
"stdclinic.skankytown.org",
"grover",
"cookiemonster.cisco1.cccp.gov",
"budweiser",
"icc.tcbc.eu",
"nucleardefense.norad.disney.com",
"thinktank.rand.com",
"gilooly",
"rampart",
"skillz.tcbytreats.com",
"radioaktivitat.de",
"scrabble",
);
print "Multex (on $whereAmI): Starting up..\n";
if ($#ARGV < 0 || $user ne "root")
{
die("\n Usage: $0 <command to distribute>\n\n Note:
+ You must be root to use this command. Example: $0 ls -l foo* \n\n
+");
}
while(++$argCounter!=$#ARGV+1)
{
$commandName=$commandName." ".$ARGV[$argCounter];
}
$commandName=$ARGV[0].$commandName;
}
if($whereAmI eq $arbiter)
{
foreach $box (@hosts)
{
#print "Multex (on $whereAmI): Executing [$com
+mandName] on [$box]..\n";
open (THISBOX,"rsh $box $commandName |");
@resultText=<THISBOX>;
close (THISBOX);
foreach $line (@resultText)
{
print "Multex: Output from $box: $line
+";
}
}
}
else
{
print "Multex (on $whereAmI): Distributing command..Pl
+ease wait.\n";
open (ORIGINALBOX,"rsh $arbiter /usr/local/bin/multex
+$commandName |");
@resultText=<ORIGINALBOX>;
close(ORIGINALBOX);
foreach $line (@resultText)
{
print "$line";
}
}
}
sub spinDownRoutine()
{
print "Multex (on $whereAmI): Spinning down..\n";
exit; # bonk
}