rgb96 has asked for the wisdom of the Perl Monks concerning the following question:

Hey, all. I'm just tyring to write a simple script using Net::SSH::Perl to log onto another computer and execute a program on there. It doesn't run the other program, and I'm not really sure why, just wondering if you guys could give me some help. Oh yeah, I setup the SSH so that I don't need a password and it just uses public keys.

#!/usr/bin/perl -w use Net::SSH::Perl; use strict; my $ssh = Net::SSH::Perl->new("xx.x.xx.xxx"); $ssh->login("gbonner"); $ssh->cmd("cd AATv2"); $ssh->cmd("perl getEnvs.pl");

Replies are listed 'Best First'.
Re: ssh trouble
by salva (Canon) on Mar 10, 2009 at 19:34 UTC
    It's failing because Net::SSH::Perl starts a new session for every command it runs. Try...
    $ssh->cmd("cd AATv2 && perl getEnvs.pl");
      Thanks, so much. That fixed it. I had read that, but I thought it said it only did that for ssh protocol1 and if you didn't give it a protocol, it defaulted to 2, but I must have been wrong.
Re: ssh trouble
by toolic (Bishop) on Mar 10, 2009 at 18:54 UTC
    I have no idea what your problem might be, but a quick look at the docs for Net::SSH::Perl reveals that you might be able to get more information about why it is failing:
    my ($out, $err, $exit) = $ssh->cmd("perl getEnvs.pl"); print "exit: $exit\n"; print "error: $err\n"; print "output: $out\n";

    Tip #11 from Basic debugging checklist

      okay,thanks. I tried that and got an output of "2". any idea what that means?

        2 is the code for POSIX error ENOENT - file not found - see Error.

        A user level that continues to overstate my experience :-))
        No idea. I updated my node. You should print out all 3 pieces of information (out, err, exit). What do you expect them to be? When you run your getEnvs.pl script, what do you expect its output to be? You probably expect its exit status to be 0, right? Also, does your "cd AATv2" command succeed?