Help creating expect script for manifest upload

  • 1
  • Question
  • Updated 2 months ago
  • Answered
Looking to create a command script in HPNA to automate manifest upload via tftp server to multiple devices.

I found an expect script on HPNA (below) which i modified a bit (ip, manifest file name) but executing it results in it hanging on the "Please type 'yes' or 'no':" prompt after the copy tftp command. 

Appreciate any feedback on how to correct this please. 

again, this is not my work, just trying to understand how it's working to fine tune it for this purpose.

https://github.com/Lynkdev/Expect-learning/tree/master/Ruckus




Photo of Lynkdev

Lynkdev

  • 3 Posts
  • 0 Reply Likes

Posted 2 months ago

  • 1
Photo of Jeronimo

Jeronimo

  • 327 Posts
  • 38 Reply Likes
I'm not shell script expert, but I think the main reason below is blank.

<expression>
send "copy tftp system-manifest *.*.*.* FI08070e_Manifest.txt all-images-secondary\r"
set more true
expect {
     -ex "$more_prompt" {
                   send " " exp_continue
      } $config_prompt {
      } $prompt {
      }
}

<blank>
$config_prompt {
      } $prompt { 
      }

That means if you met $config_prompt, then do nothing({}), and if you met $prompt, then also do nothing({}).

Try to modify and test.
Photo of Jeronimo

Jeronimo

  • 327 Posts
  • 38 Reply Likes
Try to modify like below.

expect { 
     -ex "y*n" { 
                   send "y/r"
      exp_continue 
      } $config_prompt {
      } $prompt { 
      }
}

That means if you met 'yes or no' then type y and enter.

And retrun to expect top(the expect {}).

In breief, the expect loop is used at mutiple condition.

1) yes or no is y enter

2) if you met 1), retrun to first again, 

3) If you don;t met 1), proceed next condition ; $config_prompt {} -> $prompt {}.

And next continously....
(Edited)
Photo of Lynkdev

Lynkdev

  • 3 Posts
  • 0 Reply Likes
Thanks for the reply. This does make sense and I tried running with below changes: 

I removed $config_prompt as this is being run through enable mode, it's set as unknown anyways. Is this correct?

send "copy tftp system-manifest *.*.*.* FI08070e_Manifest.txt all-images-secondary\r"
set more true
expect {
 -ex "y*n" {
 send "y\r"
 exp_continue
 } $prompt {
 }
}

Posted full results from the output below. I also noticed that after running this command script, it takes about two minutes just to show the send "copy tftp" command in the log output as it's running.

https://github.com/Lynkdev/Expect-learning/blob/master/Ruckus/Results%20from%20Expect%20script


Not sure what the # check for previous logout portion of the script is doing towards the bottom, is this needed?



Photo of Lynkdev

Lynkdev

  • 3 Posts
  • 0 Reply Likes
Thanks for the reply. This does make sense and I tried running with below changes: 

I removed $config_prompt as this is being run through enable mode, it's set as unknown anyways. Is this correct?

send "copy tftp system-manifest *.*.*.* FI08070e_Manifest.txt all-images-secondary\r"
set more true
expect { 
 -ex "y*n" { 
 send "y\r" 
 exp_continue 
 } $prompt { 
 }
}

Posted full results from the output below. I also noticed that after running this command script, it takes about two minutes just to show the send "copy tftp" command in the log output as it's running.

https://github.com/Lynkdev/Expect-learning/blob/master/Ruckus/Results%20from%20Expect%20script


Not sure what the # check for previous logout portion of the script is doing towards the bottom, is this needed?