Junos OS

last person joined: 7 days ago 

Ask questions and share experiences about Junos OS.
  • 1.  Determining whether number is odd or even in Slax

    Posted 06-21-2010 13:50

      I have a situation in which I would like to do a 'show route <x>' and would like to perform a test on the outgoing interface returned for the active route.

     

    The test I would like to perform is whether the subinterface of the outgoing interface is either even or odd.  So I suppose two questions would be, would Slax convert a string into a number depending on the context of the operation being performed on it...and is there an elegent (or any) way to test for evenness or oddness?



  • 2.  RE: Determining whether number is odd or even in Slax
    Best Answer

    Posted 06-21-2010 14:40

    SLAX does automatically convert strings into numbers as required (or it tries to at least). The following code is an example of how you could achieve your objective. A mod result of 1 indicates it is odd, 0 indicates it is even:

     

            var $interface-name-1 = "ge-0/0/1";
            var $interface-name-2 = "ge-0/1/2";
            
            var $digits-1 = translate( substring-after( $interface-name-1, "-" ), "/", "" );
            var $digits-2 = translate( substring-after( $interface-name-2, "-" ), "/", "" );
            
            <output> $digits-1 mod 2;
            <output> $digits-2 mod 2;

     



  • 3.  RE: Determining whether number is odd or even in Slax

    Posted 06-22-2010 08:13

    Thanks for the reply, I haven't had time to implement this, but it looks like it will do the trick.