11: Scripts
EMG™ Edge Management Gateway User Guide
229
proc.stdin.write(b'set radius state enable\n')
proc.stdin.flush()
while True:
output_str = proc.stdout.readline()
if b'RADIUS settings successfully updated' in output_str:
break
elif b'set radius' not in output_str:
# RADIUS command returned an error
s1 = str(output_str)
s2 = s1.split("\\r")[1]
print("RADIUS command returned: " + s2.split("\\n")[0])
proc.stdin.close()
proc.terminate()
proc.wait()
sys.exit(1)
print("RADIUS settings updated and enabled.")
proc.stdin.close()
proc.terminate()
proc.wait()
sys.exit(0)
Python Custom Script - EMG CLI Session
An example of a Python Custom Script that uses the Pexpect module to interact with the CLI
session and the device ports to detect the prompt on any devices connected to the EMG, and set
the device port name to be the same as the device prompt:
#! python
# Script to detect the prompt on a device connected to an EMG device
port,
# and set the device port name to the prompt. Punctuation characters are
# removed and the device port number is appended to the name. Prompts
ending
# in '>' are detected. For example, for a Cisco device attached to device
# port 3 and displays this prompt:
# engcisco_cat3560>
# the name for device port 3 will be set to "engcisco_cat3560-3"
import pexpect
import datetime
import time
import sys
import re
now = datetime.datetime.now()
print("Detecting devices on EMG at ", end="")
print(now.strftime("%Y-%m-%d %H:%M"))
# start the CLI session to get number of device ports
p=pexpect.spawn('clisession -U sysadmin')