rConfig - Expect Script Example
Overview
The example below is based on an Expect script to connect to a Radware Alteon load balancer, and dump its configuration.
SIE Feature setup
To get started with the SIE feature, you must first enable it in rConfigs .env file. Otherwise any scripts that are called using the methods below will not run. This must be completed by someone with root access to the rConfig Server.
- Login to the rConfig Server
- Edit the .env file
- Save and exit
- Clear the app cache
Script parameters
As of V7.0 rConfig support 5 parameters that can be sent to the script for use within your code. These are;
{script_path}
{device_ip}
{device_username}
{device_password}
{device_enable_password}
We will see later how to use these when calling the script.
Deploy script to server
When deploying a script to the server it is assumed 1) that is was tested on the rConfig server itself, and 2) the binary to run the script is present. You will need the binary path later.
Finding Binary paths on Rocky Linux
To locate the binaries for expect
, perl
, bash
, and Python 3
on your Rocky Linux server, you can use the which
command. Here’s how to do it for each:
Expect:
Where to deploy scripts
All scripts must be located in the following directory. Please create it if it does not exist.
Add a connection template
We have a brand new type of connection template available specifically for devices that will use scripts. See an example below. To add the new template, in rConfig UI go to Devices > Device Templates
and add a new template. Clear out the default template,
and paste in the template below. We will use this when creating our device that will use a custom script. You may need to adjust the timeout values depending on your scripts runtime.
Add command to Category
The next step in the provcess is to add the command to the category. To do this, in rConfig UI go to Devices > Commands
and add a new command.
The command will take the following format. It is advisable to set the ‘Alternate Filemane’ for this command, otherwise the resulting config file names maybe lenghty and unreadable. See screehsot below.
Lets break down the command. The first part if the path to the binary, the second is the name of the script which must be prafaced by the variable {script_path}
. Following the script name, you can enter the above
variables in any order, and none are mandatory. They just depend on the parameters that your script expect. You will see in this example, the parameters are {device_ip}
, {device_username}
, and {device_password}
, and the
{device_enable_password}
is not called.
We have a sample expect script below, and the above command will call that script with the parameters that we set in the script.
There are several great tutorials online on how to develop expect scripts, this is a good one by Digital Ocean that explains the basics. https://www.digitalocean.com/community/tutorials/expect-script-ssh-example-tutorial
New command with scriptAdd to the device
Now, all thats requied is to add the connection template and the correct cateogry (which contains the command we just added) to the device.
Run tests
We have tried to keep the setup and tests as ‘rConfig’ as possible. This means, to test the script, you can simply run the debug command in rConfig as you would with SSH and telnet connections.
Github Repo
As with all rConfig open standards, we will keep as many examples of the scripts and templates in the repo as possible. Please visit our public templates repo at https://github.com/rconfig/rConfig-templates. We will preface all SIE scripts and templates with SIE in the directory name.