That would work except for the fact we need to check it against more than one value.
So to do so I end up having to create an if statement for each assortment of blanks vs non-blanks Eg: Case 1: If bgp-communities=blank & bgp-local-pref=blank & bgp-med=blank & bgp-origin=blank & bgp-prepend=blank then do *ip route add dst-address=$dstaddress gateway=$gateway* *Case 2: If bgp-communities=valid! & bgp-local-pref=blank & bgp-med=blank & bgp-origin=blank & bgp-prepend=blank then do ip route add dst-address=$dstaddress gateway=$gateway + bgp-comm..* *Case 3: If bgp-communities=blank & bgp-local-pref=valid! & bgp-med=blank & bgp-origin=blank & bgp-prepend=blank then do ip route add dst-address=$dstaddress gateway=$gateway + bgp-local-p* *Case 4: If bgp-communities=blank & bgp-local-pref=blank & bgp-med=valid! & bgp-origin=blank & bgp-prepend=blank then do ip route add dst-address=$dstaddress gateway=$gateway + bgp-med..* so on and so forth to account for every possible combination Quote: "*Now it would be easy enough to just write 2 /ip route add statements based on bgp-local-pref however I'm actually trying to work with a number of the bgp values so for each value I'd be required to write a number more /ip route add statements (for 5 attributes, 32 statements are required*)" Kind Regards, Andrew Cox AccessPlus - Head Network Administrator Ph: 1300 739 822 (7am - 12 midnight AEST) On 12 December 2010 04:05, Scott Reed <sr...@nwwnet.net> wrote: > if ([:len $bfplocalpref > 0) > > > /ip route add dst-address=$dstaddress gateway=$gateway $bgplocalpref > > else > > > /ip route add dst-address=$dstaddress gateway=$gateway > end if > > or > if ([:len $bfplocalpref> 0) > > > /ip route add dst-address=$dstaddress gateway=$gateway $bgplocalpref > if ([:len $bfplocalpref<= 0) > > > /ip route add dst-address=$dstaddress gateway=$gateway > > > With whatever syntax is correct. > > > On 12/11/2010 11:14 AM, Andrew Cox wrote: > >> Hi guys, >> >> Back with another script-related query today [image: :-)] >> >> I've got this up as a thread in the forum too if anyone wants to reply >> there, will be posting whatever solution I come across to help others - >> http://forum.mikrotik.com/viewtopic.php?f=9&t=47393 >> >> ---- >> Trying to write a section of code that will allow me to take a variable >> and >> allow it to be inserted (or not inserted) as part of an 'add' command on a >> RouterOS device. >> >> Example: >> >> *Code:* >> /ip route add dst-address=192.168.1.0/24 gateway=192.168.0.254 >> >> vs >> *Code:* >> /ip route add dst-address=192.168.1.0/24 gateway=192.168.0.254 >> bgp-local-pref=1111 >> >> >> I want to be able to run this command from inside a script, which in >> itself >> is easy enough, however the "src-address" value (or other values) should >> only be included if they exist. >> >> The way I'm trying to do this currently works like so, I read/define each >> value throughout the script then when I get to the add command I use all >> of >> these values at once like so >> >> *Code:* >> /ip route add dst-address=$dstaddress gateway=$gateway >> bgp-local-pref=$bgplocalpref >> >> >> which then gives me an error as although I can enter a blank value for >> bgp-local-pref in a terminal window, having it do so from a script causes >> an >> error. >> >> *Code:* >> ad...@mikrotik]> ip route add >> dst-address=192.168.1.0/24gateway=192.168.0.254 bgp-local-pref= >> >> [ad...@mikrotik]> system script run test >> >> invalid value for bgp-local-pref, an integer required >> [ad...@mikrotik]> >> >> >> As you can see, the terminal accepts no value fine.. while the test script >> (listed below) causes an error. >> >> *Code:* >> :local dstaddress "192.168.1.0/24" >> :local gateway "192.168.0.254" >> :local bgplocalpref >> >> /ip route add dst-address=$dstaddress gateway=$gateway >> bgp-local-pref=$bgplocalpref >> >> >> So, I figure.. why not just check if the value exists at all and if not >> don't call it as part of the command. >> >> *Code:* >> /ip route add dst-address=$dstaddress gateway=$gateway [:if ([:len >> $bgplocalpref]> 0 ) do={bgp-local-pref=$bgplocalpref}] >> >> >> However this doesn't work either. Now it would be easy enough to just >> write >> 2 /ip route add statements based on bgp-local-pref however I'm actually >> trying to work with a number of the bgp values so for each value I'd be >> required to write a number more /ip route add statements (for 5 >> attributes, >> 32 statements are required). >> >> So.. I went for an alternative solution: set the values to be part of the >> command as well. >> >> *Code:* >> :if ([:len $bgplocalpref]> 0 ) do={:set bgplocalpref >> "bgp-local-pref=$bgplocalpref"} >> >> /ip route add dst-address=$dstaddress gateway=$gateway $bgplocalpref >> >> >> However this also simply generates an error (I'd expected that it'd just >> continue on with the 'add' command if there was no value assigned to the >> variable. >> >> Out of ideas now.. anyone else run into this before? >> >> >> Kind Regards, >> Andrew Cox >> AccessPlus - Head Network Administrator >> Ph: 1300 739 822 (7am - 12 midnight AEST) >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL:< >> http://www.butchevans.com/pipermail/mikrotik/attachments/20101212/66825d0c/attachment.html >> > >> _______________________________________________ >> Mikrotik mailing list >> Mikrotik@mail.butchevans.com >> http://www.butchevans.com/mailman/listinfo/mikrotik >> >> Visit http://blog.butchevans.com/ for tutorials related to Mikrotik >> RouterOS >> >> > -- > Scott Reed > Owner > NewWays Networking, LLC > Wireless Networking > Network Design, Installation and Administration > Mikrotik Advanced Certified > www.nwwnet.net > (765) 855-1060 > > > _______________________________________________ > Mikrotik mailing list > Mikrotik@mail.butchevans.com > http://www.butchevans.com/mailman/listinfo/mikrotik > > Visit http://blog.butchevans.com/ for tutorials related to Mikrotik > RouterOS > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.butchevans.com/pipermail/mikrotik/attachments/20101212/1b8609a5/attachment.html> _______________________________________________ Mikrotik mailing list Mikrotik@mail.butchevans.com http://www.butchevans.com/mailman/listinfo/mikrotik Visit http://blog.butchevans.com/ for tutorials related to Mikrotik RouterOS