Expect SSH Script for a Cisco Device: Tutorial Example

Expect SSH script for a Cisco Device Tutorial Example


expect ssh scriptUsing an Expect SSH script to automate configuration on a Cisco device is easy. Expect is installed on most Unix based operating systems, like those on Mac and Linux. The way Expect works is based on two fundamental commands, send and expect.

Expect leverages Tcl as the underlying language for procedures, conditions, arithmetic expressions, loops and file I/O. There are plenty of resources online and books you can reference to customize it to reach the goal your trying to achieve. Below is a classic example that reads a list of devices and credentials from a Bash Shell script and executes commands in an Expect script.

Overview

Create a list of devices in a text file

devices.txt

Create an Expect SSH script

config.exp

Create a Bash script to pull it together

run.sh

Run the Bash script

./run.sh

See also:
Bash One-liners
Golang SSH client
SSH Password with sshpass