Using expect script to automate building firewall templates in Panorama

L0 Member

Using expect script to automate building firewall templates in Panorama

Hi Community,


I have been struggling with this for weeks, and have tried various means, including setting the Panorama CLI parameters. However, I always get random results, which ends up either the cmdline was entered prematurely or truncated. A support ticket was logged but proved to less than helpful, as the answer given was to lessen the number of lines in the text file. The script will read in a text file with the commandlines to be run. I have use the similar script and run against SRX, and i do not encountered any issue with such. Please help.


Contents of my expect script:

#!/usr/bin/expect -f
# Set up various other variables here ($user, $password)
set force_conservative 0

log_file -noappend sendlog.log

if {$force_conservative} {
set send_slow {1 1}
proc send {ignore arg} {
exp_send -s -- $arg

set timeout 60
spawn $env(SHELL)
match_max 100000

set user [lindex $argv 0]
set password [lindex $argv 1]
set host [lindex $argv 2]
set exec [lindex $argv 3]
set exp_internal 1

# Iterate over the cmdline
proc sendcmds {PA_CMD} {
send -- "$PA_CMD\r"
expect -exact "# "

# Get the commands to run, one per line
spawn ssh $user@$host
expect -exact "Password: "
send -- "$password\r"
expect -exact "> "
send -- "set cli terminal width 200\r"
expect -exact "> "
send -- "set cli terminal type xterm\r"
expect -exact "> "
send -- "configure\r"
expect -exact "# "

set fr [open $exec r]
while {[gets $fr line] != -1} {
sendcmds $line
sleep 1
close $fr

# Tidy up
expect -exact "# "
send -- "exit\r"
expect -exact "> "
send -- "exit\r"

Tags (2)
L5 Sessionator

Hi Benson,


can you share a sample usage that you attempted? Where does it break, what output do you get, how far does it work?





L0 Member

Hi Luciano,


Thanks, i have managed to resolve the issue, there is a scripting mode in panorama which i need to turn it on. After I have done that, everything plays out nice.





Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the Live Community as a whole!

The Live Community thanks you for your participation!