#!/usr/bin/perl

@allhosts = ("pastwatch", "fission", "susten", "lucky");

if (@ARGV == 0) {
  print <<EOF
$0 [-h host1] [-h host2 ...] command ...
If no host is specified, runs command on all hosts in cluster.
[@allhosts]
EOF
;
  exit -1;
}

$somehosts = 0;
@hosts = ();
$command = "";
while ($_ = shift(@ARGV)) {
  if (/-h/) {
     push(@hosts, shift(@ARGV));
     $somehosts = 1;
  } else {
     $command .= "$_ ";
  }
}

@hosts = @allhosts unless $somehosts;
foreach $h (@hosts) {
  $com = "ssh $h \"$command\"";
  print "$com\n";
  system $com;
}
