[j-nsp] commit scripts / slax
Cheikh-Moussa Ahmad
acm at axians.de
Thu Feb 26 11:59:31 EST 2009
Hi Guys,
thanks for your quick reply. Now it works, as I want it. I didn't knew that it is so easy.
My mistake was that I used for every for-each statement the whole path.
for-each(interfaces/interface) {
if(statement) {
for-each(interfaces/interface/unit) {
This is not working and through your examples I saw it immediately.
Thanks for your help and have a good day,
Ahmad
Von: Jonathan Looney [mailto:jonlooney at gmail.com]
Gesendet: Donnerstag, 26. Februar 2009 17:40
An: Cheikh-Moussa Ahmad
Cc: juniper-nsp at puck.nether.net
Betreff: Re: [j-nsp] commit scripts / slax
This will select all units and check each unit to see if it has a description equal to "blah":
for-each(interfaces/interface) {
for-each(unit) {
if (description=="blah") {
var $int-unit = ../name _ "." _ name;
/* Check to see if the int-unit is configured in OSPF, LDP, etc. */
}
}
}
I believe the above is equivalent to:
for-each(interfaces/interface/unit) {
if (description=="blah") {
var $int_unit = ../name _ "." _ name;
/* Check to see if the int-unit is configured in OSPF, LDP, etc. */
}
}
Which is also equivalent to:
for-each(interfaces/interface/unit[description=="blah"]) {
var $int_unit = ../name _ "." _ name;
/* Check to see if the int-unit is configured in OSPF, LDP, etc. */
}
(Note that the square brackets perform a comparison at that level and only select items matching that comparison. In this case, it performs a comparison at the unit level and only selects units with a description equal to "blah".)
If you wanted to allow the special description to be at either the interface or unit level, and perform the check on all units that had the description or were units of an interface with the description, I believe this would work:
for-each(interfaces/interface/unit[../description == "blah" || description=="blah"]) {
var $int_unit = ../name _ "." _ name;
/* Check to see if the int-unit is configured in OSPF, LDP, etc. */
}
(That will select all units where the parent node - in this case, the interface - has a description equal to "blah", or where the unit node itself has a description equal to "blah".)
Alternatively, you could also use starts-with(field,pattern) to make a more flexible match. This will select all units where the parent node - in this case, the interface - has a description that starts with "blah", or where the node itself has a description that starts with "blah":
for-each(interfaces/interface/unit[starts-with(../description, "blah") || starts-with(description, "blah")]) {
var $int_unit = ../name _ "." _ name;
/* Check to see if the int-unit is configured in OSPF, LDP, etc. */
}
As you can see, you have lots of choices. :-)
DISCLAIMER: This was all freehand, so there may be typos. :-)
-Jon
2009/2/26 Cheikh-Moussa Ahmad <acm at axians.de<mailto:acm at axians.de>>
Hi Guys,
I have a question regarding slax scripting. I have a script, which searches for a special
description in the main interface and then check, whether unit 0 from this particular interface
is configured under ospf and ldp. Now this works fine, but the drawback of the script is that it
only checks the unit 0. My first idea was to concat the for-each statement, but unfortunately
this doesn't work. I'am not really familiar with slax and it is new stuff for me.
Anyone has an idea, how to concat for-each statements in slax, or does anyone has a better idea/hint
to solve this ? It should be something like this :
for-each (statemet) {
if(description == '****') {
for-each (statement) {
check if interface is configured in protocolls
}
}
}
Regards,
Ahmad
Sitz der NK Networks & Services GmbH: Von-der-Wettern-Straße 15, 51149 Köln
Registergericht: Amtsgericht Köln, Registernummer HRB 30805
Geschäftsführer: Tonis Rüsche
_______________________________________________
juniper-nsp mailing list juniper-nsp at puck.nether.net<mailto:juniper-nsp at puck.nether.net>
https://puck.nether.net/mailman/listinfo/juniper-nsp
Sitz der NK Networks & Services GmbH: Von-der-Wettern-Straße 15, 51149 Köln
Registergericht: Amtsgericht Köln, Registernummer HRB 30805
Geschäftsführer: Tonis Rüsche
More information about the juniper-nsp
mailing list