#!/usr/bin/perl -w
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#NAME
#  sshloop - Loop calling ssh
#
#SYNOPSIS
#  sshloop [delay] [file]..
#
#REQUIRES
#
#DESCRIPTION
#
#OPTIONS
#
#EXAMPLES
#
#FILES
#
#BUGS
#
#SEE ALSO
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

$| = 1;
$exitstat = 0;
($P = $0) =~ s".*/"";
$V = $ENV{"V_$P"} || $ENV{"D_$P"} || 2;	# Verbose level.
$delay = 600;

if ($ARGV[0] =~ /^\d+$/) {
	$delay = int($ARGV[0]);
	shift @ARGV;
}
print "$P: $delay-sec delay.\n" if $V>0;
while (1) {
	$cmd = "ssh ". join(' ',@ARGV);
	print "cmd: $cmd\n" if $V>1;
	system $cmd;
	$exitstat = $? if $? != 0;
	sleep $delay;
}

print "$P: Exit with status $exitstat.\n" if $V>1;
exit $exitstat;
