switch configuration for iter mode
[debian6500.git] / master / opt / script / configure_switch
CommitLineData
b3f3562f
OL
1#!/usr/bin/expect
2
3# ============================================================================
4#
5# Copyright (C) THALES. All rights reserved
6# Author: Laurent Mazet
7#
8# Script de configuration du switchs
9#
10# 2013-10-10 V1.0 : Creation
11#
12# ============================================================================
13
14set host [lrange $argv 0 0]
15if { $host == "" } {
757c2d98 16 puts "usage: configure_switch \[sw1|sw2|swg1|swg2|swm\]"
b3f3562f
OL
17 exit 1
18}
19
20set tftpserver ""
21if { $host == "swg1" } { set tftpserver "10.133.26.160" }
22if { $host == "swg2" } { set tftpserver "10.133.26.160" }
23if { $host == "swm" } { set tftpserver "10.133.28.160" }
8a1c6cff
OL
24if { $host == "sw1" } { set tftpserver "10.133.26.160" }
25if { $host == "sw2" } { set tftpserver "10.133.26.160" }
a991c7ba 26if { $host == "sw" } { set tftpserver "10.133.26.160" }
b3f3562f
OL
27if { $tftpserver == "" } { puts "unknown switch '$host'"; exit }
28
29set date [ exec date +%Y%m%d-%H:%m:%S ]
30set backup "$host-$date.txt"
31
32spawn telnet $host
33
34set timeout 30
35
36expect {
37 "Password:" { send "thales\r" }
38 incorrect { send_user "invalid password or account\n"; exit 1 }
39 timeout { send_user "connection to $host timed out\n"; exit 1 }
40 eof { send_user "connection to host failed\n"; exit 1 }
41}
42expect -exact ">" { send "enable\r" }
43expect "Password:" { send "thales\r" }
44expect "#" { send "copy running-config tftp://$tftpserver/$backup\r" }
45expect -exact "?" { send "$tftpserver\r" }
46expect -exact "?" { send "$backup\r" }
47expect "#" { send "copy tftp://$tftpserver/$host.txt startup-config\r" }
48expect -exact "?" { send "startup-config\r" }
49#expect "#" { send_user " << reload or exit ? >> "; interact }
50expect "#" { send "reload\r" }
51
52exit 0
53# vim:set tabstop=4 expandtab shiftwidth=4: