using expect script to execute command on palo alto firewall

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

using expect script to execute command on palo alto firewall

L0 Member

Hello, I'm using the code below to get ha state on my palo alto firewall but the output is not ok, there is a loop one the command and extra output caracters.
I'm using it with ansible in this scenario: ansible connect to a jumthost that execute this expect script on the palo alto device

#!/usr/bin/expect
set send_human {.1 .3 1 .05 2}
set network_expect_instructions_prompt "@.*>"
set network_expect_instructions_exitcode_wrong_password "2"
set network_expect_instructions_time_to_sleep "3"
set network_expect_instructions_timeout "30"
set timeout "30"
set network_target_pass "$env(NETWORK_TARGET_PASS)"

# commands communes de connectivités
spawn ssh -o StrictHostKeyChecking=no user@paloalto

expect {
-re "Password:" {
if { 0==1 } { puts "prompt ok!!"}
send -h "$network_target_pass\r"
}
timeout {
puts "no password: prompt"
set exit_code 3
if { $exit_code!=0 } { exit $exit_code }
}

}

# commandes de l'instructions
puts "EXPECT_BEGIN\r"

expect {
-re "$network_expect_instructions_prompt" {
if { 0==1 } { puts "prompt ok!!"}
send -h "show high-availability state\r"
}
timeout {
puts "prompt $network_expect_instructions_prompt not found."
set exit_code 3
if { $exit_code!=0 } { exit $exit_code }
}

}
expect {
-re "$network_expect_instructions_prompt" {
if { 0==1 } { puts "prompt ok!!"}
send -h "exit\r"
}
timeout {
puts "prompt $network_expect_instructions_prompt not found."
set exit_code 3
if { $exit_code!=0 } { exit $exit_code }
}

}
puts "EXPECT_END\r"


Here is the output

user@paloalto> show high-availability state\r
\r\u001b[K\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000user@paloalto> show \r\u001b[K\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000user@paloalto> show high-availability \r\u001b[K\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000user@paloalto> show high-availability state \r\u001b[K\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000user@paloalto> show high-availability state \r

0 REPLIES 0
  • 562 Views
  • 0 replies
  • 0 Likes
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 LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!