hello monks of the perl kind.. I am trying to login into two boxes consecutively and run commands within the same script and I am getting the error back stating perl double_login.pl -sh: clock: not found box161:~ # IllegalState: you don't have a valid SSH connection to the server at double_login.pl line 91 I am not entirely sure about if creating a second ssh object in the script should work : any ideas?
#!/usr/bin/perl #$Expect::Exp_Internal = 1; #$Expect::Debug = 1; use strict; use warnings; #use diagnostics; use Net::SSH::Expect; use Expect; my $ssh = Net::SSH::Expect->new ( host => "probe161", user => 'root', password => 'admin', raw_pty => 1, timeout => 1 ); #eval { my $login_output = $ssh->login(); if ($login_output !~ /Welcome/) { die "Login has failed. Login output was $login_output"; } #}; my ($command_file, $commands)= undef; #Open the file with the commands to be issued open(FILE, "input/clock") or die("Unable to open file"); my @commands = <FILE>; close (FILE); $ssh->exec("stty raw -echo"); my $command_run =undef; my @commands_run =(); close (FILE); #Issue the commands from the command file foreach my $command1 (@commands){ chomp $command1; $command_run = $ssh->exec($command1); print $command_run; } chomp $commands[0]; $ssh->close(); my $ssh2 = Net::SSH::Expect->new ( host => "probe140", user => 'root', password => 'admin', raw_pty => 1, timeout => 1 ); open(FILE, "input/CNE_clock") or die("Unable to open file"); my @commands2 = <FILE>; close (FILE); $ssh2->exec("stty raw -echo"); #line 91 my $command_run2 =undef; my @commands_run2 =(); #Issue the commands from the comand file foreach my $command2 (@commands2){ chomp $command2; $command_run2 = $ssh2->exec($command2); print $command_run; } $ssh2->close(); # END OF CODE SEGMENT

In reply to logging into 2 boxes with Net::Expect::ssh and 1 script by sqspat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.