Expect Script Examples#

This section shows some examples of scripts entered into a Configuration Template for device/ios/Script that can be used in a Provisioning Workflow to run the script. The examples show the usage of macros and variables.

Consider the following script snippet:

spawn telnet {{ pwf.ios_details.host }}  23\n

If the Provisioning Workflow from which the script is executed contains a context variable called ios_details with a value called {{data.Ios.* || direction:local}}, then the device host will be the value of the data.Ios instance in the current hierarchy.

Consider the following script snippet:

send "ping {{data.Countries.ios-country_code | country_name: 'South Africa'}}\r"\n

The script will be:

send "ping ZA\r"\n

Consider the following multi-line macro called IOS_enable:

expect "HQ>\r"
send "enable\r"
expect "Password:\r"
send  "{{device_details.enable_password}}\r"

The macro in a multiline script needs to be entered on a single line - without line breaks.

If we had macros for other snippets called IOS_login and IOS_show_clock, then the Configuration Template Expect Script value can be entered as these three macros:

{{IOS_login}}{{IOS_enable}}{{IOS_show_clock}}