02f76b210004760274dde35a6a4e360bf47ae5f5
[debian6500.git] / master / opt / script / set_mediatray.tcl
1 #!/usr/bin/expect
2
3 # ============================================================================
4 #
5 # Copyright (C) THALES. All rights reserved
6 # Author: Laurent Mazet
7 #
8 # Script de connection au switchs
9 #
10 # 2014-10-06 V1.0 : Creation
11 #
12 # ============================================================================
13
14 # default value
15 set blade {0}
16 set host ""
17 set login "admin"
18 set password "thalescom02"
19 set prompt "system>"
20
21 proc usage {script_name rc} {
22 puts "usage: [exec basename $script_name] \[host\] \[-b blade\] \[-h\] \[-l login\] \[-p password\] \[-x prompt\]"
23 exit $rc
24 }
25
26 # process argument
27 set action ""
28 for {set i 0} {$i < [llength $argv]} {incr i} {
29 set arg [lindex $argv $i]
30 switch $arg {
31 -b { set action "-blade" }
32 -h { usage $argv0 0 }
33 -l { set action "-login" }
34 -p { set action "-password" }
35 -x { set action "-prompt" }
36 default {
37 switch $action {
38 -blade { set blade $arg }
39 -login { set login $arg }
40 -password { set password $arg }
41 -prompt { set prompt $arg }
42 default { set host $arg }
43 }
44 set action ""
45 }
46 }
47 }
48 if {$action != ""} {
49 puts "missing arguments"
50 exit 1
51 }
52 if { $host == "" } {
53 usage $argv0 1
54 }
55
56 # start connection
57 spawn telnet $host
58
59 # login
60 expect {
61 "username:" { send "$login\r" }
62 timeout { send_user "connection to host failed\n"; exit 1 }
63 eof { send_user "connection to host failed\n"; exit 1 }
64 }
65
66
67 # password
68 expect {
69 "password:" { send "$password\r" }
70 timeout { send_user "connection to host failed\n"; exit 1 }
71 eof { send_user "connection to host failed\n"; exit 1 }
72 }
73
74 expect {
75 "$prompt" { send "mt -b $blade\r" }
76 "username:" { send_user "connection to host failed\n"; exit 1 }
77 }
78
79 expect {
80 "OK" { send "exit\r" }
81 "$prompt" { send_user "error\n"; exit 1 }
82 }
83
84 send_user "\n"
85 exit 0
86 # vim:set tabstop=4 shiftwidth=4 softtabstop=4: