Scripting question.....

  • 0
  • 1
  • Question
  • Updated 3 years ago

Almost done with a script that is modifying settings on sites for standardization.  It touches about 3000+ devices, one if statement found online parses the script and XOS devices go one way, Extremeware another.  Works great.  Now I need to add some conditional statements that will look at the IP and determine if it ends in a certain octet....


So something like

If a device IP ends in X.X.X.6 do this

blah

else this

blah

end


Unable to find the resources online to accomplish this.....should be just one line. Any input?


ty


Photo of Jimmy

Jimmy

  • 650 Points 500 badge 2x thumb

Posted 3 years ago

  • 0
  • 1
Photo of eyeV

eyeV

  • 2,484 Points 2k badge 2x thumb
What language have you chosen? Do you use XOS CLI Scripting or something else?
Photo of Jimmy

Jimmy

  • 650 Points 500 badge 2x thumb

XOS scripting.

Photo of eyeV

eyeV

  • 2,484 Points 2k badge 2x thumb
I reckon, you should use regexp TCL function. I'm not very good in TCL actually, but I recommend you to read Using CLI Scripting part in EXOS Concept Guide. There are some useful examples too.
(Edited)
Photo of Jimmy

Jimmy

  • 650 Points 500 badge 2x thumb
Ok, so I can use regexp  for something like this
if deviceip ends in .6 do this
else
 do this
end

Problem is I have no idea how to get a regexp to do this.  Having never used regular expressions before....., after researching online for 3 hours ,my head is about to explode.
Basically I would like an expression to say
dontcare.dontcare.dontcare.mustendin .6
Photo of Drew C.

Drew C., Community Manager

  • 37,322 Points 20k badge 2x thumb
RegEx is fun :)
Take a look at the IP Address examples for TCL on this page:  http://wiki.tcl.tk/989
Here's a quick and simple one you could use: ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.6$
 

It doesn't do any checks to make sure your octets are 0-255, but that doesn't seem necessary in your case since it can't be configured out-of-bounds anyway.

-Drew
(Edited)
Photo of Daniel Flouret

Daniel Flouret, Employee

  • 7,470 Points 5k badge 2x thumb
Jimmy,

An EXOS switch can have multiple IP addresses, which one are you interested in? Mgmt vlan, Default vlan?
Photo of Daniel Flouret

Daniel Flouret, Employee

  • 7,470 Points 5k badge 2x thumb
Here's a simple script that will look for the primary IP address in a vlan and store its four octets and mask in variables a, b, c, d and m.

In includes a check for vlans without configured IP address, but does not check for non-existent vlans...

set var vl $read(Input VLAN name:)
set var cli.out 0
show $vl
set var ip $tcl(split ${cli.out} "\n")
show var ip
set var e $tcl(regexp -nocase {Primary IP} $ip)
if ($e != 0) then
  set var ip $tcl(lindex $ip 6)
  set var ip $tcl(split $ip ":")
  set var ip $tcl(lindex $ip 1)
  set var ip $tcl(string trim $ip)
  set var ip $tcl(split $ip "./")
  set var a $tcl(lindex $ip 0)
  set var b $tcl(lindex $ip 1)
  set var c $tcl(lindex $ip 2)
  set var d $tcl(lindex $ip 3)
  set var m $tcl(lindex $ip 4)
endif