Daniel Berger
7/10/2007 9:16:00 PM
On Jul 10, 10:58 am, Daniel Berger <djber...@gmail.com> wrote:
> Hi all,
>
> I'm trying to automate a password reset via telnet for a report. This
> happens twice per year, and right now I'm handling things manually. My
> attempts so far have been unsuccessful.
<snip>
The documentation from Perl's Net::Telnet module suggested, for
interactive programs, to always use puts/print + waitfor. So, I went
with that approach. Here's what ultimately succeeded:
require 'net/telnet'
include Net
session = Telnet.new("Host" => host)
session.login(user, "XXXX")
session.puts("passwd")
session.waitfor(/existing login password:\s*/im)
session.puts(current_password)
session.waitfor(/new password:\s*/im)
session.puts(new_password)
session.waitfor(/new password:\s*/im)
session.puts(new_password)
session.waitfor(/password successfully changed/) # !!!
session.close
Note the multi-line regexes - that was crucial. Also, be sure to wait
for the success message. If you don't your session will close too
early and it will appear that your program succeeded, when in fact it
did not.
Regards,
Dan