add a script to color log
[debian6500.git] / master / opt / script / configure_switch_bootstrap
1 #!/usr/bin/expect
2
3 set host [lrange $argv 0 0]
4 if { $host == "" } {
5 puts "usage: configure_switch_bootstrap \[sw1|sw2|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 { $host == "sw1" } { set ipaddress "10.133.26.231" }
14 if { $host == "sw2" } { set ipaddress "10.133.26.232" }
15 if { $host == "sw" } { set ipaddress "10.133.26.231" }
16 if { $ipaddress == "" } { puts "unknown switch '$host'""; exit 1 }
17
18 spawn screen -c . /dev/ttyUSB0
19
20 set timeout 5
21
22 set state 0
23 while { $state != 1 } {
24 expect {
25 timeout { send "\r" }
26 -exact ">" { send "enable\r" }
27 "#" { set state 1 }
28 "Password:" { send "thales\r" }
29 eof { send_user "connection to host failed\n"; exit 1 }
30 }
31 }
32
33 send "configure terminal\r"
34 expect "#" { send "interface vlan 1\r" }
35 expect "#" { send "ip address $ipaddress 255.255.255.0\r" }
36 expect "#" { send "exit\r" }
37 expect "#" { send "line vty 0 4\r" }
38 expect "#" { send "password thales\r" }
39 expect "#" { send "enable password thales\r" }
40 expect "#" { send "end\r" }
41
42 # quit switch connection
43 expect "#" { send "exit\r" }
44
45 # to quit screen we need to send C-a \.
46 send "\001\\"
47 expect "kill all your windows" { send "y\r" }
48
49 exit 0
50 # vim:set tabstop=4 expandtab shiftwidth=4: