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

Martin T m4rtntns at gmail.com
Fri Jul 8 10:08:36 EDT 2016


Hi,

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:

root> file show /var/db/scripts/op/template_test.slax | no-more
version 1.1;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";

import "../import/junos.xsl";


match / {
  <event-script-results> {

    var $usb_snapshot_version_cmd = <get-snapshot-information> {
      <media> "usb0";
    }
    var $variable = jcs:invoke( $usb_snapshot_version_cmd );

    <output> $variable;
    <output> "usb0\ninvalid value";

    if( $variable == "usb0\ninvalid value" ) {
      <output> "match!";
    }

  }
}

root> op template_test | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/13.3R8/junos">
    <output>
        usb0
        invalid value
    </output>
    <output>
        usb0
        invalid value
    </output>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

root>


As seen above, "<output> $variable;" and "<output> "usb0\ninvalid
value"" provide identical output. Why doesn't "if( $variable ==
"usb0\ninvalid value" )" statement return true?


thanks,
Martin


More information about the juniper-nsp mailing list