#!/bin/perl $SIG{'QUIT'} = 'quit'; # install signal handler for SIGQUIT while ($ARGV[0] =~ /^-/) { # parse switches $ARGV[0] =~ /^-h/ && ($showhost++,$silent++,shift,next); $ARGV[0] =~ /^-s/ && ($silent++,shift,next); $ARGV[0] =~ /^-d/ && ($dodist++,shift,next); $ARGV[0] =~ /^-n/ && ($n=' -n',shift,next); $ARGV[0] =~ /^-l/ && ($l=' -l ' . $ARGV[1],shift,shift,next); last; } $systype = shift; # get name representing set of hosts while ($ARGV[0] =~ /^-/) { # we allow switches afterwards too $ARGV[0] =~ /^-h/ && ($showhost++,$silent++,shift,next); $ARGV[0] =~ /^-s/ && ($silent++,shift,next); $ARGV[0] =~ /^-d/ && ($dodist++,shift,next); $ARGV[0] =~ /^-n/ && ($n=' -n',shift,next); $ARGV[0] =~ /^-l/ && ($l=' -l ' . $ARGV[1],shift,shift,next); last; } if ($dodist) { # distribute input over all rshes? `cat >/tmp/gsh$$`; # get input into a handy place $dist = " ) { # for each line of ghosts s/[ \t]*\n//; # trim leading whitespace if (!$_ || /^#/) { # skip blank line or comment next line; } if (/^([a-zA-Z_0-9]+)=(.+)/) { # a macro line? $name = $1; $repl = $2; $repl =~ s/\+/:/g; $one_of_these =~ s/:$name:/:$repl:/; # do expansion in "wanted" list next line; } # we have a normal line @attr = split; # a list of attributes to match against # which we put into an array $host = $attr[0]; # the first attribute is the host name if ($showhost) { $showhost = "$host:\t"; } attr: while ($attr = pop(attr)) { # iterate over gh array if (index($one_of_these,":$attr:") >=0) { # is host wanted? unless ($silent) { print "rsh $host$l$n '$cmd'\n"; } $SIG{'INT'} = 'DEFAULT'; if (open(pipe,"rsh $host$l$n '$cmd'$dist |")) { # start rsh $SIG{'INT'} = 'cont'; while () { print $showhost,$_; } # show results close(pipe); } else { $SIG{'INT'} = 'cont'; print "(Can't execute rsh.)\n"; } last attr; # don't select host twice } } } unlink "/tmp/gsh$$" if $dodist; # here are a couple of subroutines that serve as signal handlers sub cont { print "\rContinuing...\n"; } sub quit { $| = 1; print "\r"; $SIG{'INT'} = ''; kill 2, $$; }