|
Linux HowTo's -
Linux Networking HowTo's
|
|
Written by Keith Short
|
|
Wednesday, 30 July 2008 06:59 |
|
This is a simple script written in Expectk. The purpose of this script is to allow entering the Telnet server name or address and the username/password combination (one time), then having the script open a telnet session, login to the Telnet server, then launch a telnet session from the telnet server to the device and drop you on a command prompt. As stated in the title, the prompts are what's to be - expected (get it, expected, Expect script? - ahh, forget it :) - from a Cisco IOS device using username/password authentication.
Syntax for running the script would be:
mytelnet device, where you've named the script "mytelnet", and "device" is the hostname or IP Address of the device you want to telnet to through via the Telnet server. So here's the script.
#!/usr/bin/expectk -f
exp_send_user "What telnet server?"
expect_user -re "(.*)\n" {set hostaddress $expect_out(1,string)}
exp_send_user "Username?"
expect_user -re "(.*)\n" {set username $expect_out(1,string)}
exp_send_user "Password?"
stty -echo
expect_user -re "(.*)\n" {set password $expect_out(1,string)}
spawn -noecho telnet $hostaddress
expect "NAS Login:"
exp_send "$username\r"
expect "Password:"
exp_send "$password\r"
expect "NAS>"
exp_send "telnet [lindex $argv 0]\r"
expect {
Username: {exp_send "$username\r"
expect "Password"
exp_send "$password\r"}
}
interact
exit
|
|
Last Updated ( Wednesday, 30 July 2008 07:39 )
|