Hi, I want to change password of root on remote machine using "NET::SSH::Expect". Per the module writer's release notes on CPAN, we have to use "send...waitfor...send" combination to work with interactive commands. In my case, the "send" part just never seem to work. The way my script is going, it looks like it completely overlooks "send" statement.
Here is my code:
#!/usr/bin/perl use strict; use warnings; use Net::SSH::Expect; my $ssh = Net::SSH::Expect-> new ( host => "10.10.10.10", password => "abcdefg", user => "root", raw_pty => 1, timeout => 3 ); my $login_output=$ssh->login(); if ( $login_output =~ /Last/ ) { print "The login was successful \n"; print "Let's change the password of root on remote server now \n"; $ssh->send("passwd"); $ssh->waitfor('password:\s',10) or die "Where is the password promp +t??"; $ssh->send("new_pass"); $ssh->waitfor('password:\s*\z',10) or die "Where is the password pr +ompt??"; $ssh->send("new_passwd"); } else { die "Log in attempt failed with $! \n"; }
to check whether my script is *actually* reading "send" statement, I ran following and it ignored it completely.
$ssh->send("find /");
but below "exec" statement works just fine.
$ssh->exec("find /");
Hence I tried using "exec" for change password in above script, but it always dies with the error that i have mentioned in the script "Where is the password prompt??" please help.
Thanks.In reply to Run interactive commands with "Net::SSH::Expect" by slayedbylucifer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |