Skip to content
Guides & References

Get your server ready for scripts

Choose between Expect, Python, Netmiko and bash for SIE scripts, install their dependencies so the web user can run them, and test the way rConfig runs them.

Script Integration EngineUpdated
On this page

Get your server ready for scripts

Most SIE problems in the field are not in the script logic. They come from the environment: a library installed for root but not for the web user, an SSH host key that can’t be saved, a key file the scheduled run can’t read. This page covers which tool to pick for which job, and how to set each one up so the scheduled run behaves like your test run.


Which tool to use

Tool Use it when Watch out for
Expect The device has an interactive CLI with menus, “press any key” screens or a pager you have to drive by hand. Everything the session prints reaches stdout unless you control it. See the Expect recipe.
Python, standard library REST APIs and JSON, with no extra packages to install or keep updated. urllib is verbose. Worth it for scripts that must keep working after server upgrades.
Python with Netmiko An SSH CLI that Netmiko already has a driver for, where the driver deals with the login quirks for you. Netmiko must be installed where the web user can import it. See Python libraries.
bash with ssh Running a handful of read-only commands over SSH with key authentication. No password authentication without extra tools. Use keys.

For other languages and frameworks (Perl, PowerShell, Node.js, Go, Scrapli, NAPALM, NETCONF), see pick a language.

Pick the simplest one that works. A standard-library Python script has nothing to break when the server’s packages are updated. A Netmiko script saves a lot of prompt handling, at the cost of a dependency you now maintain.


Where scripts and their files live

Scripts go in the scripts folder, which the command reaches through {script_path}:

/var/www/html/rconfig8/current/storage/app/rconfig/scripts/

Because the command names the interpreter first, the script only needs to be readable by the web user, not executable. Keep anything the script needs, but must not hand out, in a subfolder the web user owns:

Terminal window
SCRIPTS=/var/www/html/rconfig8/current/storage/app/rconfig/scripts
sudo mkdir -p "$SCRIPTS/keys"
sudo chown -R apache:apache "$SCRIPTS" # www-data:www-data on Ubuntu
sudo chmod 0700 "$SCRIPTS/keys"
sudo chmod 0600 "$SCRIPTS/keys/"* # once the files are in place

Good things to keep in keys/: SSH private keys, a known_hosts file for the devices your scripts reach, and API tokens that aren’t stored on the device record.


The web user runs your scripts

Scheduled downloads, and downloads started from the UI, run as the web server user: apache on RHEL family systems and www-data on Ubuntu. The main docs cover which user runs your scripts and what to do when a script needs a file only root can read. Three things catch people out in practice.

Its home directory isn’t yours. The web user’s home is a system folder that is often not writable. Anything that expects ~/.ssh, a dotfile or a per-user package folder behaves differently from your own shell.

SSH host keys can’t be saved. For the same reason, ssh usually can’t save a device’s host key to the web user’s known_hosts. Point it at a file you control instead, and accept new keys on first contact:

-o UserKnownHostsFile=/var/www/html/rconfig8/current/storage/app/rconfig/scripts/keys/known_hosts
-o StrictHostKeyChecking=accept-new

accept-new saves a key the first time it sees a device and refuses a key that later changes, which is what you want from a backup job. Avoid StrictHostKeyChecking=no with UserKnownHostsFile=/dev/null: it hides a changed host key for good.

Root’s test run proves nothing. A script you run as root can read root’s keys and root’s Python packages. Always test as the web user.


Python libraries the web user can import

Don’t install packages with pip install --user from your own account, or into the system Python. Create a virtual environment that belongs to the scripts, outside the rConfig folder so upgrades leave it alone, and point the command at its interpreter:

Terminal window
sudo python3 -m venv /opt/rconfig-sie/venv
sudo /opt/rconfig-sie/venv/bin/pip install netmiko
sudo chmod -R a+rX /opt/rconfig-sie
# Check the web user can import it (www-data on Ubuntu)
sudo -u apache /opt/rconfig-sie/venv/bin/python -c "import netmiko; print(netmiko.__version__)"

The command in rConfig then names that interpreter:

/opt/rconfig-sie/venv/bin/python {script_path}netmiko-backup.py cisco_ios {device_ip} {device_username} {device_password} {device_enable_password}

Root owns the environment and the web user can only read it, so a script can’t change its own dependencies. Write the installed versions down (pip freeze > /opt/rconfig-sie/requirements.txt) so you can rebuild the environment after a server move.


Expect and other interpreters

Expect isn’t installed by default on most servers:

Terminal window
sudo dnf install expect # RHEL family
sudo apt install expect # Ubuntu
which expect # use this path in the command

Use full paths for interpreters in commands. Don’t rely on the web user’s PATH, which is often shorter than yours.


Test the way rConfig runs it

Test in two steps, both as the web user.

1. Run the script directly with the same arguments rConfig would pass, and check both streams and the exit code separately:

Terminal window
cd /tmp
sudo -u apache /opt/rconfig-sie/venv/bin/python \
/var/www/html/rconfig8/current/storage/app/rconfig/scripts/netmiko-backup.py \
cisco_ios 192.0.2.10 backup 'example-password' \
> /tmp/sie-stdout.txt 2> /tmp/sie-stderr.txt
echo "exit code: $?"

/tmp/sie-stdout.txt should hold exactly the config you want stored, and /tmp/sie-stderr.txt should end with your SIE-OK: line.

2. Run a real download for the device, still as the web user, so the template’s timeouts and failure criteria are applied:

Terminal window
cd /var/www/html/rconfig8/current
sudo -u apache php artisan rconfig:download-device <device ID> -d # www-data on Ubuntu

Delete the two files in /tmp afterwards: they contain the device’s configuration.


Type to search.