I need to execute command on linux machine this command is interactive
command.
Interactive command means require input like [yes , no] or password
twice
my real case is.
I create a script execute commands and get the outputs successfully.
but some servers has Loging password expired so I need to interact with
server to send the current password + the new password(twice)
ssh [email protected] [email protected]’s password:
You are required to change your password immediately (password aged)
Last login: Sun Aug 7 13:15:40 2011 from 10.0.0.28
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user userName.
Changing password for userName
(current) UNIX password:
New UNIX password:
Retype new UNIX password:
Notice:
I’ve no problem in executing command in normal case
please, I have to avoid workarounds like (echo “pass” | ssh -S) to
make me pass any other interactive situations.
I’d suggest using Net::SSH::Telnet. This is a wrapper around Net::SSH
which gives an API very similar to Net::Telnet - this in turn lets you
send commands and match on the responses with regexps to decide what to
do next.
It also means you can write code which works with both telnet and ssh.
Thanks Brian,
“Net::SSH::Telnet” is has an advantage which it’s keeping the session
open until finish all commands not like “Net::SSH” which is create a
session for each command/communication.
Yes, well you have to explicitly expect the two different outcomes and
deal with them. Net::Telnet has built-in expect-like functionality.
s.cmd is basically a shortcut for “send this, then expect a prompt”. So
you need to use s.puts, expect with a regexp which matches either a
normal prompt or the password expiry, and if you get a password expiry
then deal with it appropriately.