#!/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 }

In reply to Multex - A Script For (Ex)ecuting The Same Command Across (Mult)iple Hosts by bpoag

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.