3 # $Header: gsh,v 2.0 88/06/05 00:17:20 root Exp $
5 # Do rsh globally--see man page
7 $SIG{'QUIT'} = 'quit'; # install signal handler for SIGQUIT
10 while ($ARGV[0] =~ /^-/) { # parse switches
11 $ARGV[0] =~ /^-h/ && ($showhost++,$silent++,shift,next);
12 $ARGV[0] =~ /^-s/ && ($silent++,shift,next);
13 $ARGV[0] =~ /^-d/ && ($dodist++,shift,next);
14 $ARGV[0] =~ /^-n/ && ($n=' -n',shift,next);
15 $ARGV[0] =~ /^-l/ && ($l=' -l ' . $ARGV[1],shift,shift,next);
20 do getswitches(); # get any switches before class
21 $systype = shift; # get name representing set of hosts
22 do getswitches(); # same switches allowed after class
24 if ($dodist) { # distribute input over all rshes?
25 `cat >/tmp/gsh$$`; # get input into a handy place
26 $dist = " </tmp/gsh$$"; # each rsh takes input from there
29 $cmd = join(' ',@ARGV); # remaining args constitute the command
30 $cmd =~ s/'/'"'"'/g; # quote any embedded single quotes
32 $one_of_these = ":$systype:"; # prepare to expand "macros"
33 $one_of_these =~ s/\+/:/g; # we hope to end up with list of
34 $one_of_these =~ s/-/:-/g; # colon separated attributes
37 push(@ARGV,'.grem') if -f '.grem';
38 push(@ARGV,'.ghosts') if -f '.ghosts';
39 push(@ARGV,'/etc/ghosts');
43 line: while (<>) { # for each line of ghosts
45 s/[ \t]*\n//; # trim trailing whitespace
46 if (!$_ || /^#/) { # skip blank line or comment
50 if (/^(\w+)=(.+)/) { # a macro line?
51 $name = $1; $repl = $2;
54 $one_of_these =~ s/:$name:/:$repl:/; # do expansion in "wanted" list
56 $one_of_these =~ s/:-$name:/:-$repl:/;
60 # we have a normal line
62 @attr = split(' '); # a list of attributes to match against
63 # which we put into an array
64 $host = $attr[0]; # the first attribute is the host name
66 $showhost = "$host:\t";
70 foreach $attr (@attr) { # iterate over attribute array
71 $wanted++ if index($one_of_these,":$attr:") >= 0;
72 $wanted = -9999 if index($one_of_these,":-$attr:") >= 0;
75 print "rsh $host$l$n '$cmd'\n" unless $silent;
76 $SIG{'INT'} = 'DEFAULT';
77 if (open(pipe,"rsh $host$l$n '$cmd'$dist 2>&1|")) { # start an rsh
79 for ($iter=0; <pipe>; $iter++) {
81 $remainder .= "$host+"
82 if /Connection timed out|Permission denied/;
89 print "(Can't execute rsh.)\n";
94 unlink "/tmp/gsh$$" if $dodist;
98 open(grem,">.grem") || (printf stderr "Can't make a .grem file\n");
99 print grem 'rem=', $remainder, "\n";
101 print 'rem=', $remainder, "\n";
104 # here are a couple of subroutines that serve as signal handlers
107 print "\rContinuing...\n";
108 $remainder .= "$host+";