Community discussions

MikroTik App
 
jamecollins
just joined
Topic Author
Posts: 18
Joined: Tue Apr 11, 2017 1:00 pm

Handle script error mikrotik

Thu Oct 26, 2017 6:13 am

I'm new in mikrotik Script and I have some question. Please help me resolve this:
1/ How can I get all wireless interface name in my device? Like wlan1, wlan2
2/ How can I get all SSID on my device?
3/ I have small script to remote config by using import command. That mean my device will get script from remote server and import this script on this device. I can't handle the error when my device import script. How can I handle this because I want if script import successfull, my device will send some request to my server to told that this script running successfull. I have try using command

Code: Select all

:do {
myscript
} on-error={
dosomething
}
but that not work.
Thanks for your reply.
 
User avatar
BlackVS
Member Candidate
Member Candidate
Posts: 175
Joined: Mon Feb 04, 2013 7:00 pm
Contact:

Re: Handle script error mikrotik

Thu Oct 26, 2017 7:52 am

1.
:foreach id  in [/interface wireless find] do={
 :put [/interface wireless get $id name]
}
2.
:foreach id  in [/interface wireless find] do={
 :put [/interface wireless get $id ssid]
}
3. Absence of normal error processing in ROS script is general problem %) (due to try/catch/return codes usually ignored)
In your case I propose to put remote script importing into the separate script and when catch output of that scripts run by:
:execute script=importscript file=importres
In such case you will have file "importres" which can be analyzed for some special words like "error","success" etc
PS: but keep in mind you need wait some time after ":execute" to allow script finish. I use such trick for ftp ( Full backup script, function func_ftp, https://www.mikrotik-club.in.ua/list-of-scripts/ )
 
jamecollins
just joined
Topic Author
Posts: 18
Joined: Tue Apr 11, 2017 1:00 pm

Re: Handle script error mikrotik

Thu Oct 26, 2017 9:58 am

1.
:foreach id  in [/interface wireless find] do={
 :put [/interface wireless get $id name]
}
2.
:foreach id  in [/interface wireless find] do={
 :put [/interface wireless get $id ssid]
}
3. Absence of normal error processing in ROS script is general problem %) (due to try/catch/return codes usually ignored)
In your case I propose to put remote script importing into the separate script and when catch output of that scripts run by:
:execute script=importscript file=importres
In such case you will have file "importres" which can be analyzed for some special words like "error","success" etc
PS: but keep in mind you need wait some time after ":execute" to allow script finish. I use such trick for ftp ( Full backup script, function func_ftp, https://www.mikrotik-club.in.ua/list-of-scripts/ )
Thanks alots. You really saved my day.
 
jamecollins
just joined
Topic Author
Posts: 18
Joined: Tue Apr 11, 2017 1:00 pm

Re: Handle script error mikrotik

Mon Oct 30, 2017 10:43 am

I have 2 script
Script 1: importscript. That will be import from a config file
[/import file-name="wifi.rsc"]
Script 2: check the result of importscript
:execute script="importscript" file="importresult"
:delay 5s
I try add an error on the config file and you can see that script stop, I don't get the result on importresult file.
Image
How can I handle this error?
 
User avatar
BlackVS
Member Candidate
Member Candidate
Posts: 175
Joined: Mon Feb 04, 2013 7:00 pm
Contact:

Re: Handle script error mikrotik

Mon Oct 30, 2017 10:55 am

Try
:execute script="/import file-name=\"wifi.rsc\"" file="importresult"