Commit | Line | Data |
---|---|---|
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 | ||
14 | set host [lrange $argv 0 0] | |
15 | if { $host == "" } { | |
16 | puts "usage: configure_switch.tcl \[swg1|swg2|swm\]" | |
17 | exit 1 | |
18 | } | |
19 | ||
20 | set tftpserver "" | |
21 | if { $host == "swg1" } { set tftpserver "10.133.26.160" } | |
22 | if { $host == "swg2" } { set tftpserver "10.133.26.160" } | |
23 | if { $host == "swm" } { set tftpserver "10.133.28.160" } | |
24 | if { $tftpserver == "" } { puts "unknown switch '$host'"; exit } | |
25 | ||
26 | set date [ exec date +%Y%m%d-%H:%m:%S ] | |
27 | set backup "$host-$date.txt" | |
28 | ||
29 | spawn telnet $host | |
30 | ||
31 | set timeout 30 | |
32 | ||
33 | expect { | |
34 | "Password:" { send "thales\r" } | |
35 | incorrect { send_user "invalid password or account\n"; exit 1 } | |
36 | timeout { send_user "connection to $host timed out\n"; exit 1 } | |
37 | eof { send_user "connection to host failed\n"; exit 1 } | |
38 | } | |
39 | expect -exact ">" { send "enable\r" } | |
40 | expect "Password:" { send "thales\r" } | |
41 | expect "#" { send "copy running-config tftp://$tftpserver/$backup\r" } | |
42 | expect -exact "?" { send "$tftpserver\r" } | |
43 | expect -exact "?" { send "$backup\r" } | |
44 | expect "#" { send "copy tftp://$tftpserver/$host.txt startup-config\r" } | |
45 | expect -exact "?" { send "startup-config\r" } | |
46 | #expect "#" { send_user " << reload or exit ? >> "; interact } | |
47 | expect "#" { send "reload\r" } | |
48 | ||
49 | exit 0 | |
50 | # vim:set tabstop=4 expandtab shiftwidth=4: |