Commit | Line | Data |
---|---|---|
b3f3562f OL |
1 | #!/usr/bin/expect |
2 | ||
3 | set host [lrange $argv 0 0] | |
4 | if { $host == "" } { | |
5 | puts "usage: configure_switch_bootstrap.tcl \[swg1|swg2|swm\]" | |
6 | exit 1 | |
7 | } | |
8 | ||
9 | set ipaddress "" | |
10 | if { $host == "swg1" } { set ipaddress "10.133.26.231" } | |
11 | if { $host == "swg2" } { set ipaddress "10.133.26.232" } | |
12 | if { $host == "swm" } { set ipaddress "10.133.28.231" } | |
13 | if { $ipaddress == "" } { puts "unknown switch '$host'""; exit 1 } | |
14 | ||
15 | spawn screen -c . /dev/ttyUSB0 | |
16 | ||
17 | set timeout 5 | |
18 | ||
19 | set state 0 | |
20 | while { $state != 1 } { | |
21 | expect { | |
22 | timeout { send "\r" } | |
23 | -exact ">" { send "enable\r" } | |
24 | "#" { set state 1 } | |
25 | "Password:" { send "thales\r" } | |
26 | eof { send_user "connection to host failed\n"; exit 1 } | |
27 | } | |
28 | } | |
29 | ||
30 | send "configure terminal\r" | |
31 | expect "#" { send "interface vlan 1\r" } | |
32 | expect "#" { send "ip address $ipaddress 255.255.255.0\r" } | |
33 | expect "#" { send "exit\r" } | |
34 | expect "#" { send "line vty 0 4\r" } | |
35 | expect "#" { send "password thales\r" } | |
36 | expect "#" { send "enable password thales\r" } | |
37 | expect "#" { send "end\r" } | |
38 | ||
39 | # quit switch connection | |
40 | expect "#" { send "exit\r" } | |
41 | ||
42 | # to quit screen we need to send C-a \. | |
43 | send "\001\\" | |
44 | expect "kill all your windows" { send "y\r" } | |
45 | ||
46 | exit 0 | |
47 | # vim:set tabstop=4 expandtab shiftwidth=4: |