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

Hi monks,

Here's my requirement:

From linux machine write a perl script to ssh to windows machine (ip address given in the command line) and execute one exe file in windows machine.

I tried the following code:

use Net::SSH::Perl; $sshobj = Net::SSH::Perl->new($ARGV[0]); $sshobj->login("user", "password") or die "error $!\n"; ($out,$err,$ext)= $sshobj->cmd('\"C:\platform\bin\lo100cfg.exe\" -s 1 +>nul 2>&1'); print "----->$out<--\n"; print "----->$err<--\n"; print "----->$ext<--\n";
It prints the following :
-----><-- ----->C:\platform\bin\lo100cfg.exe: not found<-- ----->0<--

But this exe file is located in the given location, but still its saying exe not found... what could be the issue?

Please give your ideas...

Replies are listed 'Best First'.
Re: Net:::SSH::Perl to windows machine
by Anonymous Monk on Sep 16, 2009 at 15:38 UTC
    But this exe file is located in the given location,

    How do you know? Try checking like this

    use Net::SSH::Perl; $sshobj = Net::SSH::Perl->new( $ARGV[0] ); $sshobj->login( "user", "password" ) or die "error $!\n"; for my $cmd ( '\"C:\platform\bin\lo100cfg.exe\" -s 1>nul 2>&1', 'ls -l \"C:\platform\bin\lo100cfg.exe\"', 'ls -l "C:\platform\bin\lo100cfg.exe"', 'ls -l C:\platform\bin\lo100cfg.exe', ) { print "----->$cmd<--\n"; my ( $out, $err, $ext ) = $sshobj->cmd($cmd); print "----->$out<--\n"; print "----->$err<--\n"; print "----->$ext<--\n"; }
    I almost forgot, Use strict warnings and diagnostics or die
      Hi, As you suggested,
      use Net::SSH::Perl; $sshobj = Net::SSH::Perl->new( $ARGV[0] ); $sshobj->login( "user", "password" ) or die "error $!\n"; for my $cmd ( '\"C:\\platform\\ilo\\bin\\lo100cfg.exe\\" -s 1>nul 2>&1', 'ls -l \"C:\\platform\\ilo\\bin\\lo100cfg.exe\\"', ) { print "----->$cmd<--\n"; my ( $out, $err, $ext ) = $sshobj->cmd($cmd); print "----->$out<--\n"; print "----->$err<--\n"; print "----->$ext<--\n"; }
      Output:
      ----->\"C:\platform\ilo\bin\lo100cfg.exe\" -s 1>nul 2>&1<-- -----><-- ----->C:\platform\ilo\bin\lo100cfg.exe: not found<-- ----->0<-- ----->ls -l \"C:\platform\ilo\bin\lo100cfg.exe\"<-- ----->-rwxr-xr-x+ 1 ???????? None 172032 Jul 7 11:23 C:\platf +orm\ilo\bin\lo100cfg.exe<-- -----><-- ----->0<--

      In the above result, ls -l is showing the exe file is exists. but when i was executing the same exe, its saying "exe not found" what could be the problem?

      Thanks in Advance.
        In order to provide complete help, it is necessary to know what sshd server is running on windows. Most importantly, what shell is being executed. When you type some-command 1>nul 2>&1 you should get nothing in either stdout or stderr, as you have redirected stdout to 'nul' and sent stderr there as well. The output 'some-command: not found' is a stderr msg, which you should not be receiving.
        1. Can you run the command with no arguments or redirections?
        2. It is clear that the 'ls' command works. Can you invoke it using a full path (including the drive letter)?
        3. If you are running ssh-2, can you execute the command using a relative path, ie
          $$sshobj->cmd("cd \"C:\platform\ilo\bin\""); $$ssh->obj->cmd(".\lo100cfg.exe");
Re: Net:::SSH::Perl to windows machine
by Illuminatus (Curate) on Sep 16, 2009 at 18:54 UTC
    What are you running on the Windows machine to allow ssh access?