This can be done. You have to use :eval, which is relatively recent and I don't believe is documented in the wiki yet.
> On Mar 7, 2016, at 2:09 PM, Christopher Tyler <ch...@totalhighspeed.net> > wrote: > > The problem isn't getting the info that I need or even storing it in a > variable. If I write the script and do one interface per line, this becomes > trivial as each line would have it's own statically named variable. I however > want to keep the script as compact as possible. Thus looping through the > interfaces rather than hard coding each interface. > > If I use a static variable name like the script you referenced below, as the > loop goes through each interface, the variable gets rewritten in each > instance ending with only the value of the last interface, which is useless > for the other interfaces. Unless there is a way to dynamically create and > recall the name of the variable, then this is a non-starter and I'll have to > completely rethink my approach. I'm just not sure that the scripting language > is powerful enough to handle the task as hand as envisioned. > > If I could do something like an array "$interface[$count]", or even just some > way of appending a variable like "$interface.$count" but that doesn't work. > So unless someone has a solution, I'm stuck. > > -- > Christopher Tyler > MTCRE/MTCNA/MTCTCE/MTCWE > Total Highspeed Internet Services > 417.851.1107 > > ----- Original Message ----- > From: "Scott Reed" <sr...@nwwnet.net> > To: "Mikrotik discussions" <mikrotik@mail.butchevans.com> > Sent: Monday, March 7, 2016 2:23:38 PM > Subject: Re: [Mikrotik] Script to monitor ethernet interface speed > > from the Mikrotik site > https://www.mikrotik.com/testdocs/ros/2.8/appex/scripting1.php > This should get you going with what you want to do. > > In this example, we will monitor IP address on the *ether1* interface, > and if it is changed, send an e-mail: > > /system script add name="changed-address" source={ > :if ([/system scheduler get check run-count]<=1) do={ > /system script run start-once > } > :global temp > :global b > :set temp $a > :set b [ \ > /ip address get \ > [/ip address find=interface=ether1] \ > address \ > ] > :if ($temp != $b) do={ > /tool e-mail send \ > to=exam...@example.com \ > subject="The dynamic IP gets changed" > :set a $b > } > } > > /system script add name="start-once" source={ > :global a > :set a [ \ > /ip address get \ > [/ip address find interface=ether1] \ > address \ > ] > } > > /system scheduler add name=check interval=1m on-event=changed-address > > > > On 3/7/2016 2:22 PM, Christopher Tyler wrote: >> I'm in need of a little scripting assistance. I'm trying to write a router >> script that gets the current link speed of all the interfaces on a router >> and compare that against the previous value that was received from that same >> script. >> >> Below is the script that I have so far. Right now it loops through all of >> the interfaces, checks to see if there is an active Ethernet link, then it >> gets the current rate and compares it to the string "1Gbps", if it's not >> 1Gbps it then puts a message in the log for for that interface. What I can't >> figure out is how to store a variable as part of the variable name so that I >> can compare it to the current value to see if the link changed, which is >> what I really want to know. But I need that stored value in order to check >> against it, rather than the string 1Gbps. >> >> :global identity ([/system identity get name]) >> :foreach interface in=[/interface ethernet find] do={ >> /interface ethernet monitor numbers=$interface once do={ >> :if ("$status" = "link-ok") do { >> :if ("$rate" != "1Gbps") do { >> :log info message=($name . " is set to " . $rate) >> }}}} >> >> This will eventually send an email, I just have it logging right now to keep >> my inbox from getting flooded. And before anyone says it. Yes, I know that >> the built in logging can do this, but we have over 100 routers and figuring >> out which one sent out a message is not an entirely non-time consuming task, >> and I ultimately we would like a little more information in the email than >> what the logging system provides. >> >> Any assistance is greatly appreciated. >> > > -- > Scott Reed > > Wireless Networking > Network Design, Installation and Administration > Mikrotik Advanced Certified > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > <http://mail.butchevans.com/pipermail/mikrotik/attachments/20160307/688307dc/attachment.html> > _______________________________________________ > Mikrotik mailing list > Mikrotik@mail.butchevans.com > http://mail.butchevans.com/mailman/listinfo/mikrotik > > Visit http://blog.butchevans.com/ for tutorials related to Mikrotik RouterOS > _______________________________________________ > Mikrotik mailing list > Mikrotik@mail.butchevans.com > http://mail.butchevans.com/mailman/listinfo/mikrotik > > Visit http://blog.butchevans.com/ for tutorials related to Mikrotik RouterOS -- Grand Avenue Broadband -- Wireless Internet Service Circle City to Wickenburg and surrounding areas http://grandavebb.com _______________________________________________ Mikrotik mailing list Mikrotik@mail.butchevans.com http://mail.butchevans.com/mailman/listinfo/mikrotik Visit http://blog.butchevans.com/ for tutorials related to Mikrotik RouterOS