Created
April 18, 2014 22:41
-
-
Save evan2645/11067391 to your computer and use it in GitHub Desktop.
Expect script to detect EAPS ring configuration inconsistencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect | |
#exp_internal 1 | |
set timeout -1 | |
send_user "Enter username: " | |
expect_user -re "(.*)\n" | |
set user $expect_out(1,string) | |
stty -echo | |
send_user "Enter password: " | |
expect_user -re "(.*)\n" | |
send_user "\n\n" | |
stty echo | |
set pw $expect_out(1,string) | |
set file [open [lindex $argv 0] r] | |
set hostlist [read $file] | |
close $file | |
log_user 0 | |
foreach host [ split $hostlist "\n" ] { | |
set port_list "" | |
set protected_vlans "" | |
set eaps_ports "" | |
if {"$host" == ""} { continue } | |
spawn ssh -o StrictHostKeyChecking=no "$user@$host" | |
#spawn telnet $host | |
#expect "login: $" | |
#send "$user\n" | |
expect "Enter password for $user: $" | |
#expect "password: $" | |
send "$pw\n" | |
expect "Enter password for $user: $" {send_user "Login failed!\n" ; exit} "# $" | |
send "dis clipaging\n" | |
expect "# $" | |
send "show eaps\n" | |
expect -gl "\r\n--------------------------------------------------------------------------------\r\n" | |
expect -gl "\r\n--------------------------------------------------------------------------------\r\n" | |
expect -re "Y \[ \]+(\[:0-9\]+) \[ \]+(\[:0-9\]+)" { lappend eaps_ports $expect_out(1,string) ; lappend eaps_ports $expect_out(2,string) ; exp_continue } -gl "\r\n--------------------------------------------------------------------------------\r\n" | |
expect "# $" | |
foreach port $eaps_ports { | |
if { [lsearch $port_list $port] == "-1" } { lappend port_list $port } | |
} | |
send "show eaps detail\n" | |
expect -re "\[ \t\]+(\[0-9a-zA-Z_\-\]+)\[ \t\]+\[0-9\]+\[ \t\]+\r\n" { lappend protected_vlans $expect_out(1,string) ; exp_continue } "# $" | |
foreach unique_port $port_list { | |
send "show port $unique_port info detail\n" | |
expect "VLAN cfg: \r\n" | |
#expect -re "^\t\t Name: (\[0-9a-zA-Z_\-\]+), \[0-9a-zA-Z ,.:=\t\-\]+VR-Default\r\n" { lappend configured_vlans $expect_out(1,string) ; exp_continue } "# $" { continue } | |
expect -re "^\t\t Name: (\[0-9a-zA-Z_\-\]+), \[0-9a-zA-Z ,.:=\t\-\]+VR-Default\r\n" { if { [lsearch $protected_vlans $expect_out(1,string)] == "-1" } { send_user "WARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNING\nVLAN $expect_out(1,string) configured on $host EAPS port $unique_port, but not protected!\nWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNINGWARNING\n" } else { send_user "$host: Port $unique_port VLAN $expect_out(1,string) protected.\n" } ; exp_continue } "# $" { continue } | |
} | |
#foreach vlan $configured_vlans { | |
# send_user "Checking $vlan...\n" | |
# if { [lsearch $protected_vlans $vlan] == "-1" } { send_user "VLAN $vlan configured on $host EAPS port, but not protected!\n" } | |
#} | |
send "en clipaging\n" | |
expect "# $" | |
send "exit\n" | |
close $spawn_id | |
send_user "\n" | |
} | |
send_user "Check complete.\n" | |
log_user 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment