SecureCRT is one of my favorite tools. Today I had a chance to use it in a way I didn’t expected.

The problem

A customer called with a problem: he has a radio bridge that sometimes loses connection with the remote unit.

The workaround is to reload the base unit. The process is manual: he monitors the radio bridge status and do a reload when required.

The radio bridge is not considered business critical so he doesn’t have budget to replace the equipment or troubleshoot the problem. The request was to automate the check/reload process.

The solution

I did a wide analysis of the available tools on the site: no Linux servers, no monitoring, no management platform… just a Windows server and… SecureCRT!

A quick look on SecureCRT website confirmed that it supports scripting with Python, VBScript, Jscript and PerlScript. I’m familiar with Python so it is my choice.

Teh basic idea for the script is this:

  • connect to the remote device via telnet
  • verify if the radio bridge is up
  • reload the device if radio bridge is down

The script with comments is quite self explanatory:

# $language = "Python"
# $interface = "1.0"

# Website: www.ifconfig.it
# License: https://creativecommons.org/licenses/by-sa/4.0/legalcode

def main():

# CONNECTION DATA
hostIP = "X.X.X.X"
username = "myUsername"
password = "myPassword"
enablePassword = "myEnablePassword"
prompt = "#"

# PARAMETERS
command = "sh dot11 associations"
searchString = "6cfa.8923.beef"
reloadCommand = "reload in 1 reason REMOTE_NOT_FOUND"

# LOGIN STRINGS
loginStrings = ["Username","Password:",">","Password:"]
sendString = [username,password,"enable",enablePassword]

crt.Screen.Synchronous = True

# CONNECT TO REMOTE DEVICE  
crt.Session.Connect("/telnet "+hostIP)

# AUTHENTICATE PROCESS

if (crt.Session.Connected):

i=0
for string in loginStrings:
crt.Screen.WaitForString(string)
crt.Screen.Send(sendString[i]+"\r")
i = i+1

crt.Screen.WaitForString(prompt)
crt.Screen.Send("term len 0"+"\r")

crt.Screen.WaitForString(prompt)

# EXECUTE VERIFICATION COMMAND AND GET OUTPUT
crt.Screen.Send(command+"\r")

crt.Screen.IgnoreEscape = True

result = crt.Screen.ReadString(prompt)
result.strip()

crt.Screen.IgnoreEscape = False

#SEARCH STRING IN OUTPUT

if searchString not in result:
#crt.Dialog.MessageBox("FOUND STRING")
#else:
#crt.Dialog.MessageBox("STRING NOT FOUND")
crt.Screen.Send("\r")
crt.Screen.WaitForString(prompt)
crt.Screen.Send(reloadCommand+"\r")

# EXIT THE SESSION
crt.Screen.Send("\r")
crt.Screen.WaitForString(prompt)
crt.Screen.Send("exit"+"\r")

crt.Screen.Synchronous = False

main()

This script is scheduled to run every 30 minutes on the Windows server using this syntax:

"c:\Program Files\SecureCRT\securecrt.exe" /script c:\script\checkRadioBridge.py

I’d have preferred a better implementation on a Linux machine but this works so far, the customer is happy and I learn something new: that’s a win-win!