--- /dev/null
+#!/usr/bin/expect
+
+# ============================================================================
+#
+# Copyright (C) THALES. All rights reserved
+# Author: Laurent Mazet
+#
+# Script de connection au switchs
+#
+# 2014-10-06 V1.0 : Creation
+#
+# ============================================================================
+
+# default value
+set blade {0}
+set host ""
+set login "admin"
+set password "thalescom02"
+set prompt "system>"
+
+proc usage {script_name rc} {
+ puts "usage: [exec basename $script_name] \[host\] \[-b blade\] \[-h\] \[-l login\] \[-p password\] \[-x prompt\]"
+ exit $rc
+}
+
+# process argument
+set action ""
+for {set i 0} {$i < [llength $argv]} {incr i} {
+ set arg [lindex $argv $i]
+ switch $arg {
+ -b { set action "-blade" }
+ -h { usage $argv0 0 }
+ -l { set action "-login" }
+ -p { set action "-password" }
+ -x { set action "-prompt" }
+ default {
+ switch $action {
+ -blade { set blade $arg }
+ -login { set login $arg }
+ -password { set password $arg }
+ -prompt { set prompt $arg }
+ default { set host $arg }
+ }
+ set action ""
+ }
+ }
+}
+if {$action != ""} {
+ puts "missing arguments"
+ exit 1
+}
+if { $host == "" } {
+ usage $argv0 1
+}
+
+# start connection
+spawn telnet $host
+
+# login
+expect {
+ "username:" { send "$login\r" }
+ timeout { send_user "connection to host failed\n"; exit 1 }
+ eof { send_user "connection to host failed\n"; exit 1 }
+}
+
+
+# password
+expect {
+ "password:" { send "$password\r" }
+ timeout { send_user "connection to host failed\n"; exit 1 }
+ eof { send_user "connection to host failed\n"; exit 1 }
+}
+
+expect {
+ "$prompt" { send "mt -b $blade\r" }
+ "username:" { send_user "connection to host failed\n"; exit 1 }
+}
+
+expect {
+ "OK" { send "exit\r" }
+ "$prompt" { send_user "error\n"; exit 1 }
+}
+
+send_user "\n"
+exit 0
+# vim:set tabstop=4 shiftwidth=4 softtabstop=4: