#!/usr/bin/expect -f
set timeout 300
set userId
set etacopw
set etacoPrompt bash
set i 0
set prompt "-bash-4.1\$"
set passwdCount 0
set labNum 0
set type 0
switch $argc {
0 {
puts "No lab was set"
exit 0
}
1 {
set labNum [ lindex $argv 0 ]
}
2 {
set labNum [ lindex $argv 0 ]
set type [ lindex $argv 1 ]
switch $type {
fm {
set logCmd "fm log start\r"
}
card {
set logCmd "tail -f /var/log/designlog | egrep \"card_sync|cardSync\"\r"
}
trap {
set logCmd "tail -f /var/log/traplog\r"
}
session {
}
default {
puts "wrong log type"
exit 0
}
}
}
default {
puts "wrong parameter"
exit 0
}
}
#while { $i < $argc } {
# set labNum [ lindex $argv $i ]
# puts "Login to CDMA$labNum"
# incr i 1
#}
switch $labNum {
18 {
set labIP 10.112.104.179
set labName CDMA18
}
17 {
set labIP 10.112.104.67
set labName CDMA17
}
ms1 {
set labIP 10.112.177.4
set labName Monsoon1
}
ms0 {
set labIP 10.112.104.147
set labName Monsoon0
}
hurri {
set labIP 10.112.104.24
set labName "EMERGENCY"
}
15 {
set labIP 10.112.104.61
set labName CDMA15
}
eq1 {
set labIP 10.112.181.68
set labName "Earthquake-1"
}
cdma7 {
set labIP 10.112.104.34
set labName "CDMA7"
}
gsm4 {
set labIP 10.112.104.38
set labName "GSM4"
}
chin {
set labIP 10.112.104.177
set labName "Chinook"
}
default {
puts "Lab is not supported"
exit 0
}
}
puts "Login to $labName"
# first go to etaco server
spawn ssh $userId@10.115.244.49
expect {
"Password:" {
exp_send "$etacopw\r"
exp_continue
}
$etacoPrompt {
#change title name
#only for bash, didn't support others.
#echo $SHELL to check the type
#find more in http://tldp.org/HOWTO/Xterm-Title-4.html
if { $type != 0 } {
switch $type {
fm { exp_send "echo -ne \"\\033]0; fm\\007\"\r" }
card { exp_send "echo -ne \"\\033]0; card\\007\"\r" }
trap { exp_send "echo -ne \"\\033]0; trap\\007\"\r" }
session { exp_send "echo -ne \"\\033]0; session\\007\"\r" }
}
}
exp_send "ssh mtc@$labIP\r"
expect {
"Are you sure you want to continue connecting (yes/no)?" {
exp_send "yes\r"
exp_continue
}
"Password:" {
if { $passwdCount == 0 } {
incr passwdCount 1
exp_send "mtc\r"
exp_continue
} else {
exp_send "li69nux\r"
if { ($type != 0) && ( [string compare $type "session"] != 0 ) } {
exp_continue
} else {
interact
}
}
}
"$labName cli>" {
if { [string compare $type "fm"] == 0 } {
exp_send $logCmd
interact
} else {
exp_send "sh\r"
exp_continue
}
}
"mtc@typhoon-base-unit0:~\$ " {
exp_send "su -\r"
exp_continue
}
"mtc@typhoon-base-unit1:~\$ " {
exp_send "su -\r"
exp_continue
}
"/root> " {
exp_send $logCmd
interact
}
"ssh: connect to host $labIP port 22: Connection refused" {
puts "ssh: connect to host $labIP port 22: Connection refused"
exit 0
}
}
}
}