Blog Viewer

Scripting How-To: Discovering op script arguments

By Erdem posted 08-08-2015 05:14

  
Issue

This applies to SLAX version 1.1 and higher.

 

I want to discover OP Scripts arguments. If the arguments are declared in the configuration tree, this is very easy using these commands:

 

1	edit
2	show system scripts op file my_script.slax arguments

However, if the arguments are not declared there, how can I discover OP Script arguments? I know I can use the auto complete functions in the Junos OS CLI, but I want to know if there is an automatic way to achieve this goal. I want to avoid reading the script contents to look for arguments, if possible.

 

Resolution

 

There are two ways to discover your arguments.  If you are just looking for the names of the script's published arguments, you can look at the $arguments variable directly:

 

1	for-each (slax:node-set($arguments)/argument) {
2	    message "I have argument " _ name _ " set to " _ slax:evaluate("$" _ name);
3	}

(This is using slax 1.1 features, available in Junos OS Release12.1.)

In addition, the current set of arguments is placed in the $junos-context variable:

 

01	<junos-context>
02	    <host-name>bock.juniper.net</host-name>
03	    <product>juise</product>
04	    <localtime>Tue Sep 10 14:20:13 2013</localtime>
05	    <localtime-iso>2013-09-10 14:20:13 EDT</localtime-iso>
06	    <script-type>op</script-type>
07	    <user-context>
08	        <user>phil</user>
09	        <uid>1089</uid>
10	        <op-context/>
11	        <arguments>
12	            <argument>./juise/juise</argument>
13	            <argument>-d</argument>
14	            <argument>/tmp/hoo.slax</argument>
15	            <argument>one</argument>
16	            <argument>1</argument>
17	            <argument>two</argument>
18	            <argument>2</argument>
19	        </arguments>
20	    </user-context>
21	</junos-context>

This gives the real command-line arguments, which can be more difficult to inspect.  I should put these in a more natural format, such as:

 

1	<argument name="one">1</argument>
2	<argument name="two">2</argument>

Source

 

Phil Schafer reply to Junos Automation (Scripting) forum question, answered 9-10-2013.


#opscript
#How-To
#Slax
#ScriptingHow-To

Permalink