#! /usr/local/bin/perl5
# /usr/local/perl5.002/bin/perl
#
#
$debug = 0;
$username = getlogin || (getpwuid($<))[0] ;
$rsh = "rsh";
#
# This is an experimental perl program to check on the state of machines 
# in the machines list.  Use chkserv to check on the servers.
#
# Get the list of machines
$machinelist="/home/MPI/mpich/util/machines/machines.sun4";
#
# Read command line for overrides
while ($_ = $ARGV[0]) {
    shift;
    print "Processing argument $_\n" if $debug;
    if ($_ eq "-debug") {
	$debug = 1;
	}
    elsif ($_ eq "-machinelist") {
	$machinelist = $ARGV[0];
	shift;
	}
    elsif ($_ eq "-arch") {
	$machinelist = "/home/MPI/mpich/util/machines/machines.$ARGV[0]";
	shift;
	}
    elsif ($_ eq "-user") {
	$username = $ARGV[0];
	shift;
        }
    else {
	die "Unrecognized argument $_\n";
	}
    }

if ($username eq "") {
    die "Could not get username!\n";
    }
#
#
open( FLIST, $machinelist ) || die "Could not open $machinelist" ;
# Force output to be flushed
$| = 1;
#
while (<FLIST>) {
    # Skip comment lines
    if (/^#/) { next ; }
    # remove end-of-line
    chop;
    # Remove cluster size (optional)
    ($hostname,$clustersize) = split(/:/);
    print "Read $hostname from process $$\n" if $debug; 

    system("rup $hostname");
}
close( FLIST );
0;

