Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scripting the SonicWall CLI with expect and SSH.
#!/bin/bash
# SonicWall credentials
host="XXXX"
username="admin"
password="XXXX"
# SonicWall CLI configuration
user_pattern="User:"
password_pattern="Password:"
prompt="NSA 3500>"
exit_command="exit"
newline="\n"
# the command to run
command="$1"
# use expect to establish a SonicWall CLI
# session over SSH, and then execute the
# command.
/usr/bin/expect -c "
set timeout 1
spawn ssh $host
# log into SonicWall CLI interface
expect \"${user_pattern}\"
send \"${username}${newline}\"
expect \"${password_pattern}\"
send \"${password}${newline}\"
# execute the command
expect \"${prompt}\"
send \"${command}${newline}\"
# wait for the command to complete, and then
# exit the CLI interface and terminate the
# SSH session
expect \"${prompt}\"
send \"${exit_command}${newline}\"
# the ssh session must be interactive, or else
# the SonicWall will preempt the session.
interact
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.