Page 1 of 1

Handle script error mikrotik

Posted: Thu Oct 26, 2017 6:13 am
by jamecollins
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.

Re: Handle script error mikrotik

Posted: Thu Oct 26, 2017 7:52 am
by BlackVS
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/ )

Re: Handle script error mikrotik

Posted: Thu Oct 26, 2017 9:58 am
by jamecollins
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.

Re: Handle script error mikrotik

Posted: Mon Oct 30, 2017 10:43 am
by jamecollins
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?

Re: Handle script error mikrotik

Posted: Mon Oct 30, 2017 10:55 am
by BlackVS
Try
:execute script="/import file-name=\"wifi.rsc\"" file="importresult"