Removed /usr/local from CDPATH
[clearscm.git] / test / testrexec.pl
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Getopt::Long;
6 use Pod::Usage; 
7
8 use FindBin;
9
10 use lib "$FindBin::Bin/../lib";
11
12 use Rexec;
13
14 my ($status, $cmd, @output);
15
16 my %opts = (
17   usage    => sub { podusage() } ,
18   hostname => $ENV{HOST}     || 'localhost',
19   username => $ENV{USERNAME} ? $ENV{USERNAME} : $ENV{USER},
20   password => $ENV{PASSWORD},
21   command  => 'ls /tmp',
22 );
23
24 GetOptions (
25   \%opts,
26   'usage',
27   'host=s',
28   'host=s',
29   'username=s',
30   'password=s',
31   'command=s'
32 );
33
34 if (@ARGV) {
35   $opts{command} = join ' ', @ARGV;
36 } # if
37
38 print "Attempting to connect to $opts{username}\@$opts{hostname} to execute \"$opts{command}\"\n";
39
40 my $remote = Rexec->new (
41   host     => $opts{hostname},
42   username => $opts{username},
43   password => $opts{password},
44 );
45
46 if ($remote) {
47   print "Connected to $opts{username}\@$opts{hostname} using "
48       . $remote->{protocol} . " protocol\n";
49
50   print "Executing command \"$opts{command}\" on $opts{hostname} as $opts{username}\n";    
51   @output = $remote->execute ($opts{command});
52   $status = $remote->status;
53
54   print "\"$opts{command}\" status: $status\n";
55
56   if (@output == 0) {
57     print "No lines of output received!\n";
58   } else {
59     print "$_\n" foreach (@output);
60   } # if
61 } else {
62   print "Unable to connect to $opts{username}\@$opts{hostname}\n";
63 } # if