Scripting question.....
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎04-19-2015 09:53 PM
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
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
7 REPLIES 7
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎04-20-2015 10:37 PM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎04-20-2015 07:07 PM
Jimmy,
An EXOS switch can have multiple IP addresses, which one are you interested in? Mgmt vlan, Default vlan?
An EXOS switch can have multiple IP addresses, which one are you interested in? Mgmt vlan, Default vlan?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎04-20-2015 05:16 AM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎04-20-2015 05:16 AM
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
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
