O'Reilly logo

JUNOS Automation Cookbook by Adam Chappell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

The steps for the recipe are as follows:

  1. Create the interaction procedure first. To do this, create a TCL procedure that accepts a string argument that will represent the command to run:
     proc cmdrpc { cmd } {        send -- "<rpc><command format=\"text\">[join $cmd]</command>        </rpc>\r\n"      set output ""      expect {             -re {<error-message>([^<]+)</error-message>} {              send_error "Command RPC for $cmd caused error:           $expect_out(1,string)\r\n"              return          }            -re {<(configuration-)?output[^>]*>} {               expect {                  -re {^[^<]+} {                     append output $expect_out(0,string)                     exp_continue                 }                   -re "</(configuration-)?output>" {}              }                regsub -all "&lt;" $output "<" output                regsub -all "&gt;" $output ">" output                regsub -all "&amp;" $output "&" output                return $output             } default ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required