Community discussions

MikroTik App
 
User avatar
mves
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Tue Jan 11, 2011 8:15 pm
Location: Serbia

Script help - if check?

Tue Nov 22, 2011 4:11 am

Hi guys
I need a bit command help for 2 cases...

1) I need to check interface speed in a script but can't find a proper function. I need to check interface speed.
- example:
  if interface speed=10 mbit => execute script
2) How to check if the firewall rules with certain comments are active with else for next level?
- example:
 if "1" is enabled => run script_1,
              else if "2" is enabled => run script_2,
                else if 3 "is" enabled => run script_3
Thank You for help
 
User avatar
sadeghrafie
Long time Member
Long time Member
Posts: 514
Joined: Sat Nov 14, 2009 11:28 am
Location: Bushehr, IRAN

Re: Script help - if check?

Tue Nov 22, 2011 8:21 am

1) Use Traffic Monitor Tool >> http://wiki.mikrotik.com/wiki/Manual:To ... ic_Monitor

2)
{:local i [/ip firewall filter get value-name=disabled number=[find comment=""]];
 : if (i=false) do={} else={ if () do={} else={} }
Notice that for check each firewall rule status(enable or disable), You must get the value like first one.

It's my code and maybe others come and correct or improve it.
 
User avatar
mves
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Tue Jan 11, 2011 8:15 pm
Location: Serbia

Re: Script help - if check?

Tue Nov 22, 2011 4:37 pm

I will try to make it work. I'll post results :)
But for case 1, i didn't meant for traffic, I meant interface connection status like 1Gbit, 100mbit, 10mbit :(

Thanks
 
User avatar
sadeghrafie
Long time Member
Long time Member
Posts: 514
Joined: Sat Nov 14, 2009 11:28 am
Location: Bushehr, IRAN

Re: Script help - if check?

Tue Nov 22, 2011 7:49 pm

:local i [/interface  ethernet get value-name=speed number=ether2 ]; :if (i="XXX") do={"everything you want"};
XXX can be:
1Gbps, 100Mbps, 10Mbps.
Must put them in "".
 
User avatar
mves
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Tue Jan 11, 2011 8:15 pm
Location: Serbia

Re: Script help - if check?

Tue Nov 22, 2011 8:07 pm

I've manage script to work... after each run, it's moving to next NAT setting.
{:local i [/ip firewall nat get value-name=disabled number=[find comment="1"]];
: if (i=false) do={[/system script run "enable-2"] }  else={
{:local i [/ip firewall nat get value-name=disabled number=[find comment="2"]];
: if (i=false) do={[/system script run "enable-3"] } else={ 
{:local i [/ip firewall nat get value-name=disabled number=[find comment="3"]];
: if (i=false) do={[/system script run "enable-4"] } else={
{:local i [/ip firewall nat get value-name=disabled number=[find comment="4"]];
: if (i=false) do={[/system script run "enable-5"] } else={
{:local i [/ip firewall nat get value-name=disabled number=[find comment="5"]];
: if (i=false) do={[/system script run "enable-6"] } else={
{:local i [/ip firewall nat get value-name=disabled number=[find comment="6"]];
: if (i=false) do={[/system script run "enable-mass"] } else={
/system script run "enable-1"
}} }} }} }} }} }} }}
Script runs are like this with changed enabled and disabled parts
/ip firewall nat enable [find comment="1"]
/ip firewall nat enable [find comment="1a"]

/ip firewall nat disable [find comment="2"]
/ip firewall nat disable [find comment="2a"]

/ip firewall nat disable [find comment="3"]
/ip firewall nat disable [find comment="3a"]

/ip firewall nat disable [find comment="4"]
/ip firewall nat disable [find comment="4a"]

/ip firewall nat disable [find comment="5"]
/ip firewall nat disable [find comment="5a"]

/ip firewall nat disable [find comment="6"]
/ip firewall nat disable [find comment="6a"]
First part done 8)
 
User avatar
sadeghrafie
Long time Member
Long time Member
Posts: 514
Joined: Sat Nov 14, 2009 11:28 am
Location: Bushehr, IRAN

Re: Script help - if check?

Tue Nov 22, 2011 8:11 pm

Nice job! Don't forget to five karma :lol:
 
User avatar
mves
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Tue Jan 11, 2011 8:15 pm
Location: Serbia

Re: Script help - if check?

Tue Nov 22, 2011 8:14 pm

:local i [/interface  ethernet get value-name=speed number=ether2 ]; :if (i="XXX") do={"everything you want"};
XXX can be:
1Gbps, 100Mbps, 10Mbps.
Must put them in "".

So, I had to put value that I need need to check into a local variable. That was a problem.
Thank you a lot... I will try 8)

PS... Karma added

Who is online

Users browsing this forum: Bing [Bot] and 55 guests