sqspat has asked for the wisdom of the Perl Monks concerning the following question:
#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: logging into 2 boxes with Net::Expect::ssh and 1 script
by Illuminatus (Curate) on Jul 15, 2009 at 17:16 UTC |