X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=test%2Ftestrexec.pl;h=8f0388e80af6a18bbb3ec8f157520c27f6b65b45;hb=1729e51b9b8288680eb46aed0d34808508930f52;hp=5f35bc31f9ea0aac61837b26ec140b1aad0c16a3;hpb=020a4a5ea2be725b155cae3a2cadc9aba3911b9b;p=clearscm.git diff --git a/test/testrexec.pl b/test/testrexec.pl old mode 100644 new mode 100755 index 5f35bc3..8f0388e --- a/test/testrexec.pl +++ b/test/testrexec.pl @@ -2,6 +2,9 @@ use strict; use warnings; +use Getopt::Long; +use Pod::Usage; + use FindBin; use lib "$FindBin::Bin/../lib"; @@ -10,33 +13,51 @@ use Rexec; my ($status, $cmd, @output); -my $hostname = $ENV{HOST} || 'localhost'; -my $username = $ENV{USERNAME}; -my $password = $ENV{PASSWORD}; +my %opts = ( + usage => sub { podusage() } , + hostname => $ENV{HOST} || 'localhost', + username => $ENV{USERNAME} ? $ENV{USERNAME} : $ENV{USER}, + password => $ENV{PASSWORD}, + command => 'ls /tmp', +); + +GetOptions ( + \%opts, + 'usage', + 'host=s', + 'host=s', + 'username=s', + 'password=s', + 'command=s' +); + +if (@ARGV) { + $opts{command} = join ' ', @ARGV; +} # if + +print "Attempting to connect to $opts{username}\@$opts{hostname} to execute \"$opts{command}\"\n"; my $remote = Rexec->new ( - host => $hostname, - username => $username, - password => $password, - timeout => 30, + host => $opts{hostname}, + username => $opts{username}, + password => $opts{password}, ); if ($remote) { - print "Connected to $username\@$hostname using " + print "Connected to $opts{username}\@$opts{hostname} using " . $remote->{protocol} . " protocol\n"; - - $cmd = "/bin/ls /nonexistent"; - @output = $remote->execute ($cmd); + print "Executing command \"$opts{command}\" on $opts{hostname} as $opts{username}\n"; + @output = $remote->execute ($opts{command}); $status = $remote->status; - print "$cmd status: $status\n"; - - $remote->print_lines; + print "\"$opts{command}\" status: $status\n"; - print "$_\n" foreach ($remote->execute ('cat /etc/passwd')); + if (@output == 0) { + print "No lines of output received!\n"; + } else { + print "$_\n" foreach (@output); + } # if } else { - print "Unable to connect to $username@$hostname\n"; -} # if - - + print "Unable to connect to $opts{username}\@$opts{hostname}\n"; +} # if \ No newline at end of file