[nmglug] expect

Anthony Martinez pi at pihost.us
Tue May 23 17:55:23 PDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aaron Birenboim NMOSUG wrote:
> I need a script to re-boot my router every day or so.
> Too many outages.  (Cisco 678)
> 
> Anybody have an expect script (or similar) to do this?
> 

Have some ruby:

#!/usr/bin/ruby

require 'net/telnet'
CISCO        = "10.0.0.1"
USERPASS     = "asdf"
ENABPASS     = "1234"
LOGINPROMPT  = /[Ll]ogin:/
PASSPROMPT   = /[Pp]assword:/

begin
    tn = Net::Telnet::new("Host" => CISCO,
                          "Timeout => 10)
    tn.waitfor LOGINPROMPT
    tn.cmd({"String" => USERPASS, "Match" => PASSPROMPT})
    tn.cmd "en"
    tn.cmd({"String" => ENABPASS, "Match" => PASSPROMPT})
    tn.puts "reset"  # cmd probably expects the prompt back. :P
rescue TimeoutError => fail
    warn "Rebooting may have failed: #{fail}"
end


not having a cisco device on me, it might need tweaking, especially in the
patterns. I left them as code constants. Let me know how it goes for you.

> Session would look something like:
> 
> telnet 10.0.0.1 << EOF
> userPassword
> en
> SuperUserPassword
> reboot
> EOF
> 
> of course we may need some 'expects' in between
> so the above responses come only AFTER the appropriate prompts.
> 
>             aaron
> 
> 
> 
> _______________________________________________
> nmglug mailing list
> nmglug at nmglug.org
> http://www.nmglug.org/mailman/listinfo/nmglug
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQFEc676KaiGM/xGKzQRAttBAJ9lK8aEAhl/uX7Q1frmO5DrO75QKQCfZu/k
Y80uF3PRmnR7VMDiGlC6byQ=
=Kx+C
-----END PGP SIGNATURE-----




More information about the nmglug mailing list