Community discussions

MikroTik App
 
callme
just joined
Topic Author
Posts: 14
Joined: Sat Aug 30, 2014 9:12 am

if else won't run script but run on terminal !

Mon Dec 10, 2018 7:51 am

Dear Friends,
I hope I write my issue in right place :)

I have Mikrotik RB2011 v6.43.7 with LCD display and 2 WAN (Main + Backup) input. I need switch the LCD with the active WAN port (ether1 = main link , ether2= backup link)

I create this script in system scheduler
if ([/ip route get 0 active] = true) do={/lcd interface display ether1-main} else={/lcd interface display ether2-backup}
.
The LCD won't switch, But when use the code on terminal the LCD changed and switch to ether2-backup without any problem !

Any one have idea what is the problem or how to fix that ?
I try use this code in scheduler but also facing same problem won't run script
if ([/ip route get 0 active] = true) do={/system script run LCD-Main} else={/system script run LCD-Backup}
.
Image
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: if else won't run script but run on terminal !

Mon Dec 10, 2018 8:46 am

Dear Friends,
I hope I write my issue in right place :)
Better place would be the script forum

I tried the command:
/lcd interface display ether1
on my CRS125 but nothing happens.
What should the command do?
 
callme
just joined
Topic Author
Posts: 14
Joined: Sat Aug 30, 2014 9:12 am

Re: if else won't run script but run on terminal !

Mon Dec 10, 2018 2:23 pm


I tried the command:
/lcd interface display ether1
on my CRS125 but nothing happens.
What should the command do?
.

To switch lcd reading to ether1, I need get reading the bandwidth in graphical mode for active port like this screen shot for LCD
Image

But first you should check the Default Screen is stats in LCD settings as below
Image

You can take screen shot by this command
lcd take-screenshot file-name=bandwidth
you will find a screenshot picture in Files (bandwidth.bmp)
 
Redmor
Member Candidate
Member Candidate
Posts: 256
Joined: Wed May 31, 2017 7:40 pm
Location: Italy

Re: if else won't run script but run on terminal !

Mon Dec 10, 2018 8:43 pm

I can't remember if [/ip route get 0 active] is boolean or not.
Try to :put [/ip route get 0 active] and :put [/ip route get 0 active=no], if the second doesn't return false use :len [/ip route get 0 active]>0 to trigger :if
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: if else won't run script but run on terminal !

Mon Dec 10, 2018 10:19 pm

These does not work:
:put [/ip route get 0 active=no]
expected end of command (line 1 column 29)
:len [/ip route get 0 active]>0
expected end of command (line 1 column 30
 
Redmor
Member Candidate
Member Candidate
Posts: 256
Joined: Wed May 31, 2017 7:40 pm
Location: Italy

Re: if else won't run script but run on terminal !

Tue Dec 11, 2018 8:28 am

These does not work:
:put [/ip route get 0 active=no]
expected end of command (line 1 column 29)
:len [/ip route get 0 active]>0
expected end of command (line 1 column 30
Try :if ([ :len [/ip route get 0 active]]>0), can't remember the right syntax, you also have to set right spaces to make it work.
The first one should work, or at least, I use it with running=no
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: if else won't run script but run on terminal !

Tue Dec 11, 2018 8:49 am

Both this gives true:
:put ([ :len [/ip route get 0 active]]>0)
true
:put [/ip route get 0 active]
true
And if i remove the outside wan cable
:put [/ip route get 0 active]
false
So the both could be used
 
Redmor
Member Candidate
Member Candidate
Posts: 256
Joined: Wed May 31, 2017 7:40 pm
Location: Italy

Re: if else won't run script but run on terminal !

Tue Dec 11, 2018 8:56 am

Try to write only script name instead of /system script run, I never used it to run scripts from schedulers
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: if else won't run script but run on terminal !

Tue Dec 11, 2018 9:02 am

Script does work fine.

Using a CDS125 with my PC is connected on eth1 and wan is on eth7
# dec/11/2018 07:56:06 by RouterOS 6.43.7
# software id = 8HCM-ZNY9
#
# model = CRS125-24G-1S-2HnD
# serial number = xxxx
/system script

add dont-require-permissions=no name=LCD-switch owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=\
    ":if ([/ip route get 0 active] = true) do={/lcd interface display ether1} else={/lcd interface display ether7}"

/system scheduler
add interval=10s name=SC-LCD-switch on-event=LCD-switch policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=\
    dec/11/2018 start-time=06:55:00
With the wan cable in, LCD do show eth1.
Removing wan cable, LCD changes to eth7

Script test this every 10 seconds.
Works from cli and script:
:if ([/ip route get 0 active] = true) do={/lcd interface display ether1} else={/lcd interface display ether7}
@callme
Do you really look the the LCD?
For me its just a gimmick and to do some testing with. Not for real/long time monitoring.
 
callme
just joined
Topic Author
Posts: 14
Joined: Sat Aug 30, 2014 9:12 am

Re: if else won't run script but run on terminal !

Wed Dec 12, 2018 3:25 pm

Dear Jotne and all Colleagues

When I use this command on Terminal, Run and switch the LCD without problem!
:if ([/ip route get 0 active] = true) do={/lcd interface display ether1} else={/lcd interface display ether7}
But failed to switch the LCD screen when I used in Script or Scheduler
I don't know why, maybe this is software bug on RB2011 routers. I will try on different RB2011 my be that will help :(

Thank you Redmor - that will help a lot!
Try to write only script name instead of /system script run, I never used it to run scripts from schedulers
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: if else won't run script but run on terminal !

Wed Dec 12, 2018 4:24 pm

Strange.
Does work nice on my device.
# dec/11/2018 07:56:06 by RouterOS 6.43.7
# software id = 8HCM-ZNY9
#
# model = CRS125-24G-1S-2HnD
But do you need it? Or is it just nice to have?
No one looks at the switch all time, at least I do not.

I do use Splunk as shown in my signature to monitor everything.
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: if else won't run script but run on terminal !

Wed Dec 12, 2018 7:00 pm

Never address items with index! Replace "0" with find command:
:if ([/ip route get [ find where gateway=ether1 ] active] = true) do={/lcd interface display ether1} else={/lcd interface display ether7}
Check if the condition is correct...
 
Redmor
Member Candidate
Member Candidate
Posts: 256
Joined: Wed May 31, 2017 7:40 pm
Location: Italy

Re: if else won't run script but run on terminal !

Wed Dec 12, 2018 7:15 pm

Never address items with index! Replace "0" with find command:
:if ([/ip route get [ find where gateway=ether1 ] active] = true) do={/lcd interface display ether1} else={/lcd interface display ether7}
Check if the condition is correct...
Well you can if you print :D
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: if else won't run script but run on terminal !

Wed Dec 12, 2018 8:02 pm

Never address items with index! Replace "0" with find command:
God point. I am still in learning phase using script with MT :)

May be this could be change to use default interface name, since I have change mine to some else.
:if ([/ip route get [ find where gateway=ether1-Wan ] active] = true) do={/lcd interface display ether1-Wan} else={/lcd interface display ether7}
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: if else won't run script but run on terminal !

Wed Dec 12, 2018 9:57 pm

Never address items with index! Replace "0" with find command:
:if ([/ip route get [ find where gateway=ether1 ] active] = true) do={/lcd interface display ether1} else={/lcd interface display ether7}
Check if the condition is correct...
Well you can if you print :D
That's true... But it is still prone to errors as it fails if index changes for whatever reason.
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: if else won't run script but run on terminal !

Wed Dec 12, 2018 10:00 pm

May be this could be change to use default interface name, since I have change mine to some else.
Yes, you need to change that. :wink: As said... Check the condition. :roll: (I did a quick copy and paste on my tablet and missed the changed interface name.)
 
callme
just joined
Topic Author
Posts: 14
Joined: Sat Aug 30, 2014 9:12 am

Re: if else won't run script but run on terminal !

Thu Dec 13, 2018 10:36 pm

Hi Jotne and others friends,
I'm sure now, the problem from the router have software bugs with this version:
# dec/13/2018 23:13:14 by RouterOS 6.43.7
# software id = 0ZTX-DDYY
#
# model = 2011UiAS

When I test same script on other RB2011 work without any problem
.
# dec/13/2018 23:21:54 by RouterOS 6.43.7
# software id = HJYN-KNNY
#
# model = 2011UiAS-2Hn
.
And this one also there is no problem
.
# dec/13/2018 23:24:49 by RouterOS 6.43.7
# software id = XBU4-KZFI
#
# model = 2011UiAS
.

Yes my friend I need it on my work in office. When main link down my colleagues can know the reason why the internet speed is down
Strange.
Does work nice on my device.
# dec/11/2018 07:56:06 by RouterOS 6.43.7
# software id = 8HCM-ZNY9
#
# model = CRS125-24G-1S-2HnD
But do you need it? Or is it just nice to have?
No one looks at the switch all time, at least I do not.

I do use Splunk as shown in my signature to monitor everything.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: if else won't run script but run on terminal !

Thu Dec 13, 2018 11:11 pm

Seems like you have encountered a bug. Post a message to support@mikrotik.com
Are routerboard software the same for the boxes?
Yes my friend I need it on my work in office. When main link down my colleagues can know the reason why the internet speed is down
This could be solved by using any led on the switch.
Fixed light eth1
Blink light eth2

I did try to use a script to show signal strength for one link by flassing the quality.
See here:
viewtopic.php?f=9&t=142132

Who is online

Users browsing this forum: No registered users and 146 guests