slayedbylucifer has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Run interactive commands with "Net::SSH::Expect"
by zentara (Cardinal) on Jan 10, 2011 at 12:06 UTC | |
by slayedbylucifer (Scribe) on Jan 10, 2011 at 13:28 UTC | |
|
Re: Run interactive commands with "Net::SSH::Expect"
by molecules (Monk) on Jan 10, 2011 at 15:28 UTC | |
by slayedbylucifer (Scribe) on Jan 10, 2011 at 17:45 UTC | |
by slayedbylucifer (Scribe) on Jan 13, 2011 at 11:12 UTC | |
|
Re: Run interactive commands with "Net::SSH::Expect"
by salva (Canon) on Jan 13, 2011 at 12:25 UTC | |
by slayedbylucifer (Scribe) on Jan 13, 2011 at 12:49 UTC |