Submit a ticketCall us

Webinar: Web Help Desk for HR, Facilities and Accounting Departments
This webinar will focus on use cases for HR, Facilities and Accounting.

Having a unified ticketing and asset management system for all the departments in your company can provide end-users with a seamless experience and make things easier for your IT team. Yet, with different business tasks and objectives, many departments don’t fully understand the capabilities of Web Help Desk and how the software can be customized for effective use in their departments.
Register Now.

Home > Success Center > Kiwi CatTools > Kiwi CatTools 3.11 Administrator Guide > Activities > Activities list > Device.CLI.Send commands > Example Generic Script

Example Generic Script

Table of contents
No headers
Created by Caroline Juszczak, last modified by Caroline Juszczak on Jun 28, 2016

Views: 23 Votes: 0 Revisions: 1


The script below is a more complete framework which you can use as a starting point for your external scripts.

It works in the following way:

  1.  Send a command to the device.
  2. Wait until the device finishes the output generated by the command and returns the device prompt.
  3. Parse the stored output from the device and take appropriate action.


Depending on what you need to achieve you may want to add additional 'mults' to the localSendCommandSingle

function. By also adding matching case statements you can respond to output from the device which is not

handled by the standard device script.


Option Explicit

' The starting place for the external script is always Function Main.

Function Main(inputString)

Dim commandResult

Dim processBufferResult

Main = ""

' Call the function to send the command to the device. In this case we are using input string as the command.

commandResult = localSendCommandSingle(inputString)

' If the command was processed OK then take action.

If commandResult Then

processBufferResult = ProcessBuffer()

If processBufferResult Then

' Take action based on the result of processing the buffer

End If

End If

End Function


Function localSendCommandSingle(CmdToSend)

' This is a simplified version of the send command single activity used in the main CatTools client.

' The idea is that it can be used to handle specific output not catered for by the main script.

Dim retval

Dim Mult(20)

Dim Choices

Dim StoredBuffer

localSendCommandSingle = False

StoredBuffer = ""


' Set up Mults - The text returned from the device is checked for any of the mults and

' if a match is found different actions are taken depending on the mult.

Mult(1) = "--More--"

Mult(2) = "Invalid Command"

' Custom mults can be inserted here

' Mult(3) = "Device specific mult"

Mult(18) = cl.DeviceVTYPrompt

Mult(19) = cl.DeviceEnablePrompt

Mult(20) = cl.DeviceConfigPrompt

Choices = 20 'the number of mults


' Clear the buffer



' Send the command to the device (but dont press enter yet)

If cl.WaitForEcho Then

If cl.SendAndWaitForEcho(CmdToSend) = False Then

cl.Log 4, "Did not receive echo of " & CmdToSend

Exit Function

End If


cl.sendData CmdToSend

End If


' We dont want to record the command being sent or the echo so clear the buffer ready for a reply from device



' Send <cr> to execute the command

cl.sendData vbCr


' Process return results

cl.Log 4, "Waiting for a response to: " & CmdToSend


' Wait for a response from the device

If cl.WaitForTime = 0 Or cl.WaitForTime = "" Then

' If the user has not specified a WaitForTime

retval = cl.WaitForMultData(Mult, Choices, cl.RecDataTimeOut * 5)


' If the user has specified a WaitForTime

retval = cl.WaitForMultData(Mult, Choices, cl.WaitForTime)

End If


' Store any output from the device

StoredBuffer = StoredBuffer & cl.RxBuffer


' Analyse results for the first matching mult found

Select Case retval

Case 0

' No valid data received

If 2 > 0 Then

cl.Log 2, "Did not receive expected response to command: " & CmdToSend

End If

Exit Do

Case 1

' --more-- prompt found so send a cr to get the next block of data

cl.sendData vbCr

Case 2

' Invalid command - error with syntax

If 2 > 0 Then

cl.Log 2, "Error with syntax: " & CmdToSend

End If

Exit Do

'Case 3

' Take action based on the "Device specific mult" found.

' This may involve sending a command or keystrokes to the device.

' You may also need to flush the buffer before or after the above by using a cl.FlushRxBuffer command.

' Note: You may not want to exit the loop at this point because you will want to leave the device ready

' to receive another command so you should ensure you are at a device prompt when you exit the loop.

Case 18, 19, 20

' Prompt found so the device has finished its output so exit the loop.

localSendCommandSingle = True

Exit Do

End Select


' Put the total output of the command in the RxBuffer so that it is available for use elsewhere.

cl.RxBuffer = StoredBuffer

End Function


Function ProcessBuffer()

' Do what ever processing of the data in cl.RXBuffer you need to here

ProcessBuffer = True

End Function

Last modified
07:19, 28 Jun 2016