Hello,
I am using Expect and perl to send commands to a ssh session and I now want to run a couple of commands from the command line on the machine where I am running the perl script. I have tried the code below and it does not seem to be sent to the local command line. Is there anyway of co nfirming it is actually being sent to the local command line. I know it is a simple question but I just can't see why it is not being run?
thanks for help
my $exp = new Expect;
#commands below are not being sent to the local machine command line a
+nd not sure why not?
$exp->send("ssh root\@device203 install license < input/Licence321178.
+lic\r");
print "$exp\n";
sleep(1);
$exp->send("admin\r");
sleep(1);
# This next section uses Expect and SSH successfully
my $ssh = Net::SSH::Expect->new (
host => "$host_details[1]",
user => 'root',
password => 'admin',
raw_pty => 1,
timeout => 1
);
#eval {
my $login_output = $ssh->login();
if ($login_output !~ /loginprompt/) {
die "Login has failed.
Login output was $login_output";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.