cancel
Showing results for 
Search instead for 
Did you mean: 

Script error; IF, ELSE, ENDIF

Script error; IF, ELSE, ENDIF

modris_bernands
New Contributor II
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"
endifWhen 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: Noneand 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,
5 REPLIES 5

Chad_Smith1
Extreme Employee
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.

modris_bernands
New Contributor II
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 

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!

BradP
Extreme Employee
Hi Modris,

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