11: Scripts
EMG™ Edge Management Gateway User Guide
223
# Are there any command line parameters?
if {$argc > 0} {
set location [lindex $argv 0]
}
set now [clock seconds]
set date [clock format $now -format {%D %R}]
if {$argc > 0} {
myprint "Internal temperature of the $location EMG at $date"
} else {
myprint "Internal temperature of the EMG at $date"
}
# spawn the CLI session
if {[catch {spawn -noecho clisession -U sysadmin} result]} {
abortSession 1
}
set sessionId $spawn_id
# Handle eof
expect_after {
-i $sessionId eof {
myprint "Session unexpectedly terminated."
abortSession 2
}
}
set timeout 10
log_user 0
# Wait for the first prompt
set loggedIn false
while {! $loggedIn} {
expect {
timeout {myprint "Timeout waiting to login"; abortSession 3}
"Need to specify username" {myprint "Need to specify -U ";
abortSession 4}
"*> " {set loggedIn true}
} ;
}
exp_send "\n"
expect {
timeout {myprint "Timeout waiting for CLI prompt"; abortSession 3}
-re "\n\r(\\\[\[^\r]*]>)"
}
set emgPrompt $expect_out(1,string)
# Run the temperature command
exp_send "show temperature\n"
expect {
timeout {myprint "Timeout waiting for temperature"; abortSession 3}
-re "Current Internal Temperature: (.*)\r\n"
}