Capturing Output of Commands
Macro language commands can start and stop the capture of JunosE command output
and save the results.
The env.startCommandResults command starts JunosE output capture and flushes any
existing capture buffer. The capture stops when directed by a
stop
command or when
the buffer maximum of 5,242,880 (5MB) characters is reached. The command output
in the buffer is stored as normally seen on the terminal output. A <CR> ends a line of
buffer data.
The env.stopCommandResults command stops JunosE output captures. The
env.getResults command obtains one line of output from the capture buffer.
The env.startCommandResults, env.stopCommandResults, and env.getResults
commands apply to one CLI session. There is no effect on CLI sessions other than the
CLI session running the macro.
The env.getResults command gets the next line of the capture buffer. Each call gets the
next line of the capture buffer. The command returns the first line the first time it is called
after a capture start (env.startCommandResults). It resets the next line it returns by
passing a line number argument. An argument of 0 or 1 returns the first line.
For example:
<# env.startCommandResults #>
show version
<# env.stopCommandResults #>
! possibly other JunosE commands
<# while something is true #>
<# outputLine := env.getResults #>
. . .
<# endwhile #>
Adding Regular Expression Matching to Macros
Use the following syntax to check a string against a regular expression:
env.regexpMatch(stringToMatch, someRegularExpression)
For example, the string outputLine is checked to determine whether it starts with the
value System:
<# if env.regexpMatch(outputLine, "^System") #>
. . .
<# endif #>
In this example, the string interface is checked to determine whether it has the correct
syntax:
<# interface := env.argv(1) #>
<# if env.regexpMatch(interface, "^[0-9]+/[0-9]+$") #>
. . .
<# endif #>
Copyright © 2010, Juniper Networks, Inc.
462
JunosE 11.3.x System Basics Configuration Guide
Summary of Contents for JUNOSE 11.3
Page 6: ...Copyright 2010 Juniper Networks Inc vi...
Page 8: ...Copyright 2010 Juniper Networks Inc viii JunosE 11 3 x System Basics Configuration Guide...
Page 24: ...Copyright 2010 Juniper Networks Inc xxiv JunosE 11 3 x System Basics Configuration Guide...
Page 32: ...Copyright 2010 Juniper Networks Inc 2 JunosE 11 3 x System Basics Configuration Guide...
Page 146: ...Copyright 2010 Juniper Networks Inc 116 JunosE 11 3 x System Basics Configuration Guide...
Page 166: ...Copyright 2010 Juniper Networks Inc 136 JunosE 11 3 x System Basics Configuration Guide...
Page 432: ...Copyright 2010 Juniper Networks Inc 402 JunosE 11 3 x System Basics Configuration Guide...
Page 488: ...Copyright 2010 Juniper Networks Inc 458 JunosE 11 3 x System Basics Configuration Guide...
Page 524: ...Copyright 2010 Juniper Networks Inc 494 JunosE 11 3 x System Basics Configuration Guide...
Page 554: ...Copyright 2010 Juniper Networks Inc 524 JunosE 11 3 x System Basics Configuration Guide...
Page 566: ...Copyright 2010 Juniper Networks Inc 536 JunosE 11 3 x System Basics Configuration Guide...
Page 588: ...Copyright 2010 Juniper Networks Inc 558 JunosE 11 3 x System Basics Configuration Guide...
Page 613: ...PART 3 Index Index on page 585 583 Copyright 2010 Juniper Networks Inc...
Page 614: ...Copyright 2010 Juniper Networks Inc 584 JunosE 11 3 x System Basics Configuration Guide...
Page 632: ...Copyright 2010 Juniper Networks Inc 602 JunosE 11 3 x System Basics Configuration Guide...