[j-nsp] How to catch invalid value/option for a command in SLAX script?

Phil Shafer phil at juniper.net
Sat Jul 9 13:27:22 EDT 2016


Martin T writes:
>I have a following simple SLAX script which executes "show system
>snapshot media usb0" command in an environment where "usb0" option for
>"show system snapshot" command is unavailable:

I can't reproduce this on my test box ("command is not valid on the m7i"),
but the best way to investigate this would be to use the debugger,
stop on the "==" line, and print the contents of $variable.

Reached breakpoint 2, at /tmp/foo.slax:21
foo.slax:21:     if( $variable == "usb0\ninvalid value" ) {
(sdb) p $variable
[node-set] (1)
<xnm:error xmlns="http://xml.juniper.net/xnm/1.1/xnm" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm">
<message>
command is not valid on the m7i
</message>
</xnm:error>

My guess is that the implicit string() call in the equals test is
getting you.

Consider using contain() instead of equals::

(sdb) p string($variable) == "\n\ncommand is not valid on m7i\n\n"
[boolean] false

Thanks,
 Phil


More information about the juniper-nsp mailing list