11: Scripts
EMG™ Edge Management Gateway User Guide
233
s = "set deviceport port " + str(devicePort) + " name " +
pList[devicePort - 1]
p.sendline(s)
i = p.expect([pexpect.TIMEOUT,
'Device Port settings successfully updated.\r\n'],
timeout=10)
if i == 0: # Timeout
print("Timeout waiting for response.")
devicePort = devi 1
# Terminate the CLI session
p.sendline("logout")
time.sleep(.500)
p.wait()
print("Script completed.")
sys.exit(0)
Tcl Custom Script - EMG CLI Session
An example of a Tcl Custom Script that interacts with a CLI session:
#! tcl
# Script to get the current internal temperature of the EMG
# Accepts one optional command line parameter for location
set emgTemp "unknown"
set location ""
# 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} {
puts "Internal temperature of the $location EMG at $date"
} else {
puts "Internal temperature of the EMG at $date"
}
set io [open "| clisession -U sysadmin" r+]
set loggedIn false
while {! $loggedIn} {
set len [gets $io line]
if {[string first "Invalid local user" $line] != -1} {
puts "Invalid local user passed to clisession"
break
}
if {[string first "For a list of commands" $line] != -1} {
puts $io "\n"
flush $io