ExtremeSwitching (EXOS)

  • 1.  Script error; IF, ELSE, ENDIF

    Posted 06-21-2016 13:33
    I'm newbie in scripts.
    We reconfigure our network and I try make write script for that.
    my simple script is:
    set var vlanName $CLI.ARGV1
    set var vlanDesc $CLI.ARGV2
    set var tag $CLI.ARGV3
    set var trunkport $CLI.ARGV4
    if ($CLI.ARGC ! = 0) then
    create vlan $vlanName description $vlanDesc
    configure $vlanName tag $tag
    configure $vlanName add ports $trunkport tagged
    enable $vlanName
    else
    create log entry "error with $vlanName"
    endif[/code]When I load script with 4 arguments and get errors:
    * switch1.7 # load script createvlan.xsf vlan11 gram 11 46
    Error:syntax error in expression "(4 ! = 0)"
    Error: Mismatched ELSE
    Error: Mismatched ENDIF
    [/code]additional information:
    * switch1.8 # show version
    Switch : 800243-00-03 1031G-80649 Rev 3.0 BootROM: 1.0.3.5 IMG: 12.6.2.10
    XGM2-1 :
    Image : ExtremeXOS version 12.6.2.10 v1262b10-patch1-15 by release-manager on Tue Jun 5 19:05:37 EDT 2012
    BootROM : 1.0.3.5
    * switch1.9 # show switch
    System Type: X350-48t
    * switch1.10 # show licenses
    Enabled License Level: L2 Edge
    Enabled Feature Packs: None[/code]and surprisingly is that - after script execute it really create new vlan like I want, but these errors are confused me. and that indicate on my misunderstanding about this simple script.
    without understanding simple i can't dig deeper πŸ™‚

    Q in simple - why I get:
    Error:syntax error in expression "(4 ! = 0)"
    Error: Mismatched ENDIF Error: Mismatched ELSE[/code]
    Thanks,


  • 2.  RE: Script error; IF, ELSE, ENDIF

    Posted 06-21-2016 13:48
    Hi Modris,

    For the first error, make sure that "! =" is together. It should be "!=" instead (without the quotes)


  • 3.  RE: Script error; IF, ELSE, ENDIF

    Posted 06-21-2016 13:48
    I'd check again after correcting the first error. The second errors look like they probably came from the "if" line erroring out.


  • 4.  RE: Script error; IF, ELSE, ENDIF

    Posted 06-21-2016 19:29
    Yes, Brad, You are right... remove spaces and all error is gone (for now πŸ™‚ ).

    thank You for help

    Possible I was fail becaus of example in EXOSCommandRef12_5.book.pdf

    IF ($x > 2) THENshow switch
    ELSE
    show vlan
    ENDIF[/code]
    and there are space on both side from ">", but maybe it is complete different situation. As I mention I'm complete novice in scripting πŸ˜‰


  • 5.  RE: Script error; IF, ELSE, ENDIF

    Posted 06-21-2016 19:29
    The > and != are your single operand. The switch doesn't understand what "! =" means, but it does understand "!=". I'm glad I could help. The important part is that you're taking the leap. You'll very, very rarely get a script right on the first try--but through practice, you'll get a lot better at it.

    Good job!


  • 6.  RE: Script error; IF, ELSE, ENDIF

    Posted 06-21-2016 19:46
    Modris,

    I tested the following script using your args and it works:

    set var vlanName $CLI.ARGV1set var vlanDesc $CLI.ARGV2
    set var tag $CLI.ARGV3
    set var trunkport $CLI.ARGV4
    if ($CLI.ARGC != 0) then
    create vlan $vlanName description $vlanDesc
    configure $vlanName tag $tag
    configure $vlanName add ports $trunkport tagged
    enable $vlanName
    else
    create log entry "error with $vlanName"
    endif

    I think the only notable change (other than the tabs for readability) is the one Brad mentioned above.

    You may want to consider changing if ($CLI.ARGC != 0) to if ($CLI.ARGC == 4) or some other form of argument error handling, as you really need all 4 arguments to execute this script without error.