11: Scripts
EMG™ Edge Management Gateway User Guide
219
allowed for Expect scripts includes
"fork", "open", "exp_open", "exec",
"system", "log_file", "pwd"
.
7. For scripts that return an exit code, the EMG will interpret an exit code of zero as a successful
exit code, and any non-zero exit code as an error. Non-zero exit codes are displayed (at the
CLI) or logged (for scripts that are run by the script scheduler).
Example Scripts
Interface Script—Monitor Port
The Monitor Port (Monport) script connects directly to a device port by logging into the EMG
port,
gets the device hostname, loops a couple of times to get port interface statistics, and logs out. The
following is the script:
set monPort 7
set monTime 5
set sleepTime 2
set prompt ">"
set login "sysadmin"
set pwd "PASS"
#Send CR to echo prompt
send "\r"
sleep $sleepTime
#Log in or check for Command Prompt
expect {
#Did not capture "login" or Command Prompt
timeout { send_user "Time out login......\r\n"; return }
#Got login prompt
"login" {
send_user "Logging in....\r\n"
send "$login\r"
expect {
timeout { send_user "Time out waiting for pwd
prompt......\r\n"; return }
#Got password prompt
"password" {
#Send Password
send "$pwd\r"
expect {
timeout { send_user "Time out waiting for prompt......\r\n";
return }
$prompt {}
}
}
}
}
#Already Logged in got Command Prompt
$prompt {
send_user "Already Logged....\r\n"