#!/afs/athena/contrib/perl/perl

if ($ARGV[0] eq '-do') {
    $host = `hostname`;
    chop $host;
    shift @ARGV;
    $| = 1;
    for (@ARGV) {
	print "$host: $_\n"; 
	system "$_";
    }
    exit 0;
} elsif ($#ARGV >= 0) {
    @hosts = @ARGV;
} else {
    @hosts = ('podge', 'deathtongue', 'tardis', 'portnoy', 'gevalt');
}

print "Enter bourne shell commands (beware metacharacters), dot to end:\n";
while (<STDIN>) {
      chop;
      last if $_ eq ".";
      $commands .= '"' . $_ . '" ';
}
chop $commands;

for $host (@hosts) {
    print "Connecting to $host...\n";
    system "rkinit $host";
    $cmd = "rsh $host '/bin/athena/attach " . $ENV{'USER'} . "; chdir " . $ENV{'HOME'} . 
	"; source .cshrc; sleep 1; echo hi; sleep 1; $0 -do $commands; kdestroy; sleep 3'";
    print "$cmd\n";
    system $cmd;
}

