5f2299e30134996c02c5c119c298519f22353318
3 # ============================================================================
5 # Copyright (C) THALES. All rights reserved
6 # Author: Laurent Mazet
8 # Script de connection au switchs
10 # 2013-10-10 V1.0 : Creation
12 # 2014-03-05 V1.1 : LMa ajout de passage de commande CISCO en parametre
14 # 2014-06-10 V1.2 : LMa ajout d'un fichier de commandes
16 # ============================================================================
19 set adminpassword
"thales"
22 set loginpassword
"thales"
26 puts "usage: connect_switch.tcl \[host\] \[-a adminpassword\] \[-c command\] \[-f file\] \[-h\] \[-l loginpassword\] \[-p prompt\]"
32 for {set i
0} {$i < [llength $argv]} {incr i
} {
33 set arg
[lindex $argv $i]
35 -a { set action
"-adminpassword" }
36 -c { set action
"-cmd" }
37 -f { set action
"-file" }
39 -l { set action
"-loginpassword" }
40 -p { set action
"-prompt" }
43 -adminpassword { set adminpassword
$arg }
44 -cmd { set cmd
[lappend cmd
$arg] }
46 if {[file isfile
$arg] == 1} then
{
50 foreach line
[split $data "\n"] {
51 set cmd
[lappend cmd
$line]
54 puts "can't open file '$arg'"
58 -loginpassword { set loginpassword
$arg }
59 -prompt { set prompt
$arg }
60 default { set host
$arg }
67 puts "missing arguments"
79 "Password:" { send "$loginpassword\r" }
80 timeout
{ send_user
"connection to host failed\n"; exit 1 }
81 eof { send_user
"connection to host failed\n"; exit 1 }
86 "$prompt>" { send "enable\r" }
87 timeout
{ send_user
"connection to host failed\n"; exit 1 }
88 "Password:" { send_user
"invalid login password\n"; exit 1 }
90 expect
"Password:" { send "$adminpassword\r" }
92 "$prompt#" { send "\r" }
93 "Password:" { send_user
"invalid admin password\n"; exit 1 }
96 # commands or interactive mode
97 if {[llength $cmd] == 0 } {
98 expect
"$prompt#" { interact
}
100 expect
"$prompt#" { send "terminal length 0\r" }
101 for {set i
0} {$i < [llength $cmd]} {incr i
} {
103 "$prompt#" { send "[lindex $cmd $i]\r" }
104 "confirm" { send "\r"; continue }
108 "confirm" { send "\r"; expect
"$prompt" { send "exit\r" } }
109 "$prompt" { send "exit\r" }
115 # vim:set tabstop=4 shiftwidth=4 softtabstop=4: