Extracting A Substring Based On Regular Expression Matching; Adding Global Variables For Availability To The Onerror Macro - Juniper SYSTEM BASICS - CONFIGURATION GUIDE V 11.1.X Configuration Manual

System basics configuration guide software for e series broadband services routers
Table of Contents

Advertisement

In this example, the string interface is checked to determine whether it has the correct
syntax:

Extracting a Substring Based on Regular Expression Matching

A string can be extracted from a larger string using the following syntax:
This example gets the third occurrence of a sequence of numbers followed by a
space, followed by a sequence of letters within string outputLine:
This example gets the interface value from an interface string:

Adding Global Variables for Availability to the onError Macro

Global variables can be set in any macro and retrieved without being explicitly passed
in another macro. The global variable is set with the following syntax:
The name is a quoted string and the value can be a character string or number.
The global variable is retrieved with the following syntax:
The name is a quoted string and the value is the value stored by an earlier env.setVar.
A macro can contain one onError macro. The onError macro is like any other macro
file template. There can only be one macro with the name onError in the macro file.
In this example, the macro sets a global variable before using it in a configuration
command:
<# if env.regexpMatch(outputLine, "^System") #>
. . .
<# endif #>
<# interface := env.argv(1) #>
<# if env.regexpMatch(interface, "^[0-9]+/[0-9]+$") #>
. . .
<# endif #>
env.getRegexpMatch(stringToMatch, someRegularExpression, occurrence)
<# value := env.getRegexpMatch(outputLine, "[0-9]+ [a-zA-Z]+", 3) #>
<# interface := env.getRegexpMatch(interface, "[0-9]+/[0-9]+", 1) #>
env.setVar(name, value)
value := env.getVar(name).
<# badInt #>
<# interface := "9/0" #>
<# env.setVar("interface",interface) #>
config t
interface fast <# interface; '\n' #>
ip add 7.6.5.4 255.255.255.0
Chapter 8: Writing CLI Macros
477
Writing Macros

Advertisement

Table of Contents
loading

This manual is also suitable for:

Junose 11.1

Table of Contents