07ab9959e412946db75f23a9aa60583d016659a8
[clearscm.git] / test / testrexec.pl
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use FindBin;
6
7 use lib "$FindBin::Bin/../lib";
8
9 use Rexec;
10
11 my ($status, $cmd, @output);
12
13 my $hostname = $ENV{HOST}     || 'localhost';
14 my $username = $ENV{USERNAME};
15 my $password = $ENV{PASSWORD};
16
17 my $command  = $ENV{COMMAND};
18
19 if (@ARGV) {
20   $command = join ' ', @ARGV;
21 } else {
22   $command = 'ls /tmp' unless $command;  
23 } # if
24
25 print "Attempting to connect to $username\@$hostname to execute \"$command\"\n";
26
27 my $remote = Rexec->new (
28   host     => $hostname,
29   username => $username,
30   password => $password,
31   timeout  => 30,
32 );
33
34 if ($remote) {
35   print "Connected to $username\@$hostname using "
36       . $remote->{protocol} . " protocol\n";
37
38   print "Executing command \"$command\" on $hostname as $username\n";    
39   @output = $remote->execute ($command);
40   $status = $remote->status;
41
42   print "\"$command\" status: $status\n";
43
44   if (@output == 0) {
45     print "No lines of output received!\n";
46   } else {
47     print "$_\n" foreach (@output);
48   } # if
49 } else {
50   print "Unable to connect to $username@$hostname\n";
51 } # if