Using Net::SSH::Perl to execute a set of commands



Hi,

I was trying to use Net::SSH::Perl to log into a remote box and execute a
program with pre-defined commands, something like:


#!/usr/bin/perl

use strict;
use Net::SSH::Perl;

my $ssh = Net::SSH::Perl->new("ip", debug => 0);
$ssh->login("name", "password");
my ($return) = $ssh->cmd("minicom -S mini_script_vpn.force");
print $return;

minicom is a program, and mini_script_vpn.force is a script which defined a
set of commands sent to minicom

The terminal output should be something like: (if run the program manually
from shell)

minicom -S mini_script_vpn.force
minicom: WARNING: please don't run minicom as root when not maintaining
it (with the -s switch) since all changes to the
configuration will be GLOBAL !.

Welcome to minicom 1.83.1

OPTIONS: History Buffer, F-key Macros, Search History Buffer, I18n
Compiled on May 3 2001, 22:36:07.

Press CTRL-A Z for help on special keys

Logging in..

c_fw>enable
Password:****
c_fw#Resetting VPN
configure terminal
c_fw(config)#Clear ipsec
clear crypto ipsec sa
c_fw(config)#Clear isakmp
clear crypto isakmp sa
c_fw(config)#Logging out and leaving...
Killed

But when I was running this command via the Perl Script above,

shell: RSA authentication failed: Can't load public key.
shell: Doing challenge response authentication.
shell: No challenge presented.
shell: Trying password authentication.
shell: Sending command: minicom -S mini_script_vpn.force
shell: Entering interactive session.

It quits immediately after sending command.

Any suggestion?

Thanks

Relevant Pages

  • Checking for existence of command prior to execution
    ... alone in an interactive shell it works though. ... it will fail if I add ssh to the list of commands which is ... aliased by the tcsh that is calling the above script. ...
    (comp.os.linux.misc)
  • Re: shell scripting while if string length != 0
    ... I'm not a shell guru, but pipelines don't necessarily run in sequence. ... In line 5 of your script, ... the file and wait for new commands, you may need a named pipe. ... To unsubscribe, ...
    (freebsd-questions)
  • Re: Shell Script
    ... Another valuable document to look at it the Advanced Bash Scripting Guide ... Within the script, it will change the directory to /opt, and then exit. ... THIS HAS NO EFFECT ON THE SHELL YOU RUN THIS COMMAND IN. ... Read and execute commands from FILENAME and return. ...
    (linux.redhat)
  • Re: Shell Script
    ... Within the script, it will change the directory to /opt, and then exit. ... THIS HAS NO EFFECT ON THE SHELL YOU RUN THIS COMMAND IN. ... Read and execute commands from FILENAME and return. ...
    (linux.redhat)
  • Re: Using Net::SSH::Perl to execute a set of commands
    ... > program with pre-defined commands, ... > set of commands sent to minicom ... > But when I was running this command via the Perl Script above, ... > shell: RSA authentication failed: Can't load public key. ...
    (perl.beginners)