Subject: | ogin() method does not run run_ssh() method in all cases. |
I'm using this module to automate the build and setup of virtual machine
development boxes for my job. In some instances, it is necessary for me
to alter the lilo.conf of a machine and reboot it before build can continue.
Basically, I'm doing the following
1) create new Net::SSH::Expect object
2) login
3) do some checks
4) alter lilo.conf
5) reboot
6) wait for machine to become available again
7) login
8) do more work
I was testing the ability to re-use a Net::SSH::Expect object called
$box, and I noticed that the following code throws an error:
###
my $box = Net::SSH::Expect->new (
host => 'hostname',
password=> 'xxx',
no_terminal => 1,
raw_pty => 1,
user => 'user'
);
$box->login();
$box->close();
$box->login();
my $test = $box->exec("ls -al");
print $test;
$box->close();
###
SSHAuthenticationError Login timed out. The input stream currently has
the contents bellow: at /usr/local/share/perl/5.8.8/Expect.pm line
828
The following code works, however:
###
my $box = Net::SSH::Expect->new (
host => 'hostname',
password=> 'xxx',
no_terminal => 1,
raw_pty => 1,
user => 'user'
);
$box->login();
$box->close();
$box->run_ssh();
$box->login();
my $test = $box->exec("ls -al");
print $test;
$box->close();
###
I guess what's happening is that login() only runs run_ssh() the first
time, but not the second time because it thinks the ssh process is still
running? Seems as if the solution would be to make the close() method
reset the initial state so that a subsequent login() would issue
run_ssh() again.