Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

commit-script / SLAX

‎02-13-2017 02:34 AM

Hi Guys,

 

I'm getting started with op-scripts and commit-scripts.

I want to achieve the following:

 

The Switch should write the config to a file with the filename: IP_Date_Time and copy this file to a ftp-Server.

Transfer on commit will not work because the filename is bad for or tools since it picks the Hostname instead of the IP.

 

Are there Examples? Has anyone ever done something like that?

 

 

Regards
Chris
Twitter: @chsjuniper
2 REPLIES 2
Highlighted
Junos Automation (Scripting)
Solution
Accepted by topic author CHS-929
‎02-15-2017 01:17 AM

Re: commit-script / SLAX

[ Edited ]
‎02-14-2017 05:08 AM

Hi,

 

I don't have an example to hand, but one approach to this would be:

 

1. Retrieve the config from the device using the appropriate RPC e.g. <get-configuration>

2.  Use the <exsl:document> method to write the config to a file and store it locally on the box in /var/tmp

3.  Use the RPC <file-copy> to transfer the file to the appropriate location.

 

Date and Time functions are available in SLAX so they can be leveraged to produce a suitable filename that can be used when creating the file, or transferring the file etc.

 

You can find documentation on this approach in the Juniper Day One library (https://www.juniper.net/us/en/training/jnbooks/day-one/)  which is a great starting place to learn SLAX scripting among other things.

 

Junos Automation Reference contains examples using get-configuration, as well as numerous examples of <exsl:document> or the other 4 similar functions that pretty much do the same thing.

<redirect:write>, <saxon:output>, <xsl:document> and <xt:document>

The recommendation is to use <xsl:document> as a namespace doesnt need to be defined, but the choice is yours.

 

Mastering Automation and Applying Junos Automation are also extremely valuable resources, and finally there is a great book Automating Junos Administration available on O'Reilly too (https://www.juniper.net/uk/en/training/jnbooks/oreilly-juniper-library/automating-junos-admin/)

 

Regards,

Andy

Highlighted
Junos Automation (Scripting)

Re: commit-script / SLAX

‎02-15-2017 01:18 AM

Hi Andy,

 

thank you very much for pointing me in the right direction.

 

Regards
Chris
Twitter: @chsjuniper
Feedback