Script error; IF, ELSE, ENDIF

  • 0
  • 1
  • Question
  • Updated 2 years ago
  • Answered
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
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
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
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

Thanks,
Photo of modris bernands

modris bernands

  • 610 Points 500 badge 2x thumb

Posted 2 years ago

  • 0
  • 1
Photo of Brad Parker

Brad Parker, Technical Support Engineer

  • 3,266 Points 3k badge 2x thumb
Hi Modris,

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

Brandon Clay, Escalation Support Engineer

  • 13,086 Points 10k badge 2x thumb
I'd check again after correcting the first error. The second errors look like they probably came from the "if" line erroring out.
Photo of modris bernands

modris bernands

  • 610 Points 500 badge 2x thumb
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

and there are space on both side from ">", but maybe it is complete different situation. As I mention I'm complete novice in scripting ;-)
(Edited)
Photo of Brad Parker

Brad Parker, Technical Support Engineer

  • 3,266 Points 3k badge 2x thumb
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! 
Photo of Chad Smith

Chad Smith, Senior Escalation Support Engineer

  • 5,620 Points 5k badge 2x thumb
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.
(Edited)