Hello guys !
Im using latest MT v3.1 on x86 … i try to make script which will be work like backup route in case that my ADSL connection is down.
This is script … but it is not work … so please can somebody help me?
Hm I was for testin disable my ADSL interface and run script manualy and nothing is hapening … MyRoute is still disabled … Does anybody have some other idea?
I dont see errors in my log …
microtiks are very fussy about spacing and the way you type stuff into the script.
:local pppoe1-status ([/interface pppoe-client get [/interface find comment="ADSL"] running])
:if ($pppoe1-status=false) do {/ip route enable [/ip route find comment="myRoute"]}
:if ($pppoe1-status=true) do {/ip route disable [/ip route find comment="myRoute"]}
What I do usually for the script because there is no compiler I take each line and paste it into a test router I have on my desk and check each line indivitually so I can narrow the line with the error.
But when i put this first part in terminal I have no errors , so I think that this is OK
:local pppoeStatus ([/interface pppoe-client get [/interface find comment=“ADSL”] running]);
But when i put second line in terminal:
Hm… you are right, but now my script look OK … but still is not work … when I disable my ADSL interface and run script it will not enable my backup route …
Do you have some idea what is wrong? or somebody other?
ADD: I am not certain that first line will work. What is returned with the ‘find’ parameter is an array of unique “pointers” to the data. I don’t think that pointer will be in the “/ip pppoe-client” section also. I would change the variable pppoe to global so you can see what it is returning. It may not be what you expect. If all you need to check is the interface up and running, then:
If you need to check the pppoe status instead, then change the first line to:
:global pppoe [/interface pppoe-client find name=“adsl” running]
Or maybe this:
:global adsl [/interface get [/interface find comment=“adsl” running] name]
:global pppoe [/interface pppoe-client find interface=$adsl running]
Both must be running.
The script detectors that the interface is not running and changes the username and password but then even if the account is running is will change the username and password to the next one.
Your first line is the problem. You cannot cross-link these pointers. It won’t work like that. If you use find and get, they MUST BE in the same place.
This is best. Includes error checking on the interfaces:
Notice how the get and find in the first line are preceded by the same location “/interface”. You cannot use ‘find’ in one directory and then use ‘get’ in another. Use them both in the same place, then use the result of the ‘get’ in that location to ‘find’ the interface in ‘/interface pppoe-client’.
If you want to recheck the status of the connections, the routines must be run from the start, including the data assignments, or it will use the data you got from the first ‘find’.
I did not verify the rest of the code. I just used the log entries to show where the pass and fail routines should be put. And you shouldn’t use ‘:put’ in your script unless testing. It doesn’t work unless the script is run in a shell.
ADD: If you want to run this every minute, which seems to be your goal, use the /system scheduler to run the script every minute.