Skip to content

Instantly share code, notes, and snippets.

@mortn
Last active August 29, 2015 14:09
Show Gist options
  • Save mortn/8d93294760cf85c3d126 to your computer and use it in GitHub Desktop.
Save mortn/8d93294760cf85c3d126 to your computer and use it in GitHub Desktop.
Expect script for vlan tagging on 4 HP Procurve (Really have to find a better way)
#!/usr/bin/env expect
set CTRLZ \032
set action [lindex $argv 0]
set vlan [lindex $argv 1]
if {[llength $vlan] == 0} { exit 0; }
if {$vlan < 3000} { exit 0; }
if {$vlan > 9100} { exit 0; }
stty -echo
send_user -- "Gimme Passwordz: "
expect_user -re "(.*)\n"
send_user "\n"
stty echo
set pass $expect_out(1,string)
send_user "Will $action VLAN $vlan\r\n"
set timeout 2
set ip 172.16.1.10
spawn telnet "$ip"
expect "*assword:"
send "$pass\r"
expect "*Press any key to continue*"
send "\r"
expect "core*"
send "conf\r"
expect "core*(config)"
send "vlan $vlan\r"
expect "core*(vlan-$vlan)#"
send "tagged 10,a1,a2\r"
expect "core*(vlan-$vlan)#"
send "wr mem\r"
expect "core*"
send "$CTRLZ"
expect "core*"
send "$CTRLZ"
expect "core*"
send "$CTRLZ"
expect "Do you want to log out*"
send "y"
send_user "\n"
set ip 172.16.1.11
spawn telnet "$ip"
expect "*assword:"
send "$pass\r"
expect "*Press any key to continue*"
send "\r"
expect "core*"
send "conf\r"
expect "core*(config)"
send "vlan $vlan\r"
expect "core*(vlan-$vlan)#"
send "tagged trk1,a1,a2\r"
expect "core*(vlan-$vlan)#"
send "wr mem\r"
expect "core*"
send "$CTRLZ"
expect "core*"
send "$CTRLZ"
expect "core*"
send "$CTRLZ"
expect "Do you want to log out*"
send "y"
send_user "Done\n"
set ip 172.16.1.12
spawn telnet "$ip"
expect "*assword:"
send "$pass\r"
expect "*Press any key to continue*"
send "\r"
expect "core*"
send "conf\r"
expect "core*(config)"
send "vlan $vlan\r"
expect "core*(vlan-$vlan)#"
send "tagged Trk10,a1,a2\r"
expect "core*(vlan-$vlan)#"
send "wr mem\r"
expect "core*"
send "$CTRLZ"
expect "core*"
send "$CTRLZ"
expect "core*"
send "$CTRLZ"
expect "Do you want to log out*"
send "y"
send_user "Done\n"
set ip 172.16.1.13
spawn telnet "$ip"
expect "*assword:"
send "$pass\r"
expect "*Press any key to continue*"
send "\r"
expect "core*"
send "conf\r"
expect "core*(config)"
send "vlan $vlan\r"
expect "core*(vlan-$vlan)#"
send "tagged trk9,trk11,a1,a2\r"
expect "core*(vlan-$vlan)#"
send "wr mem\r"
expect "core*"
send "$CTRLZ"
expect "core*"
send "$CTRLZ"
expect "core*"
send "$CTRLZ"
expect "Do you want to log out*"
send "y"
send_user "\r\nDone\r\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment