#!/usr/bin/expect -f # # Copyright (c) 2002, New Edge Networks, Steven "xinu" Klassen # # $Id: nenlogin,v 1.4 2002/09/12 22:49:37 xinu Exp xinu $ # ###################################################################### # Path to telnet. set telnetprog [exec which telnet]; # Leave this blank, and you will be prompted. set tacacs_login ""; # Leave this blank, and you will be prompted. set tacacs_password ""; # Leave this blank, and you will be prompted. set enable_password ""; ##-- Do NOT change anything below here unless you know what you're doing. --## # If they didn't specify, ask them discretely. if {[regexp ^\$ $tacacs_login]} { stty -echo send_user "login? " expect_user -re "(.*)\n" send_user "\n" set tacacs_login $expect_out(1,string) } if {[regexp ^\$ $tacacs_password]} { stty -echo send_user "password? " expect_user -re "(.*)\n" send_user "\n" set tacacs_password $expect_out(1,string) } if {[regexp ^\$ $enable_password]} { stty -echo send_user "enable password? " expect_user -re "(.*)\n" send_user "\n" set enable_password $expect_out(1,string) } # Deal with the arguments. set host [lindex $argv 0] set iface [lindex $argv 1] set commands [lrange $argv 2 end] # Parse out the command list. set cmdlist [split $commands ","] # Open the router up and log in. spawn $telnetprog $host expect "sername:" send "$tacacs_login\r" expect "assword:" send "$tacacs_password\r" expect ">" send "enable\r" send "$enable_password\r" # If they specified and interface, show it. if {![regexp ^\$ $iface]} { expect "#" send "sh int ser $iface\r" } ; # is the host non-empty? # Run through the comma-delimited commands. foreach command $cmdlist { expect "#" send "$command\r" } interact