Created
December 2, 2013 20:46
-
-
Save rbewley4/7758687 to your computer and use it in GitHub Desktop.
Scripting the SonicWall CLI with expect and SSH.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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