Page 1 of 1

Script to disable, wait some seconds and enable an interface

Posted: Fri Aug 24, 2012 2:04 pm
by matiasvidoni
Hi there
I want to put some lines in a netwatch monitor to check for an ip.
If that ip is not responding, run the script that has to do something like this:
disable interface ether0
wait 5 seconds
enable interface ether0
check ip
loop if necesary

Hope there is an easy solution.
Thanks
Matias

Re: Script to disable, wait some seconds and enable an inter

Posted: Fri Aug 24, 2012 4:05 pm
by nmaton
i have done the same and used the following command :



/tool netwatch
add disabled=no down-script="interface eoip enable eoip-tunnel1\r\
\n/interface eoip enable eoip-tunnel2\r\
\n/interface eoip enable eoip-tunnel3" host=10.1.1.254 interval=1s timeout=1s50
up-script="interface eoip disable eoip-tunnel1\r\
\n/interface eoip disable eoip-tunnel2\r\
\n/interface eoip disable eoip-tunnel3"

However i have noticed that netwatch doesnt do it always ... sometimes it works sometimes it doesnt .

Maybee some expert knows a better way to do this??

Re: Script to disable, wait some seconds and enable an inter

Posted: Fri Aug 24, 2012 5:26 pm
by matiasvidoni
I don't think your advice will work, as I am pinging a host behind the interface I want to disable.
So if I disable it, I can not do the ScriptUp script.
I want to disable, wait some time, then enable and test the host again.
Thanks btw :)

Re: Script to disable, wait some seconds and enable an inter

Posted: Fri Aug 24, 2012 5:53 pm
by boen_robot
The looping is what complicates this most...

You can simply use:
/interface disable ether0
:delay 5
/interface enable ether0
as your down script, but as written, it would only try this one.

Re: Script to disable, wait some seconds and enable an inter

Posted: Fri Aug 24, 2012 10:11 pm
by Ivoshiee
As much I recall you can not address ports directly and use a item index for that.
I use Netwatch tool with that script:
http://forum.mikrotik.com/viewtopic.php ... 95#p328995

Re: Script to disable, wait some seconds and enable an inter

Posted: Fri Aug 24, 2012 10:41 pm
by psamsig
Try give this a spin:
/system script
add name="Restart ether0" \
    source=":global runningRestartEther0\r\
    \n:if ([:len \$runningRestartEther0] = 0 || \$runningRestartEther0 = 0) do\
    ={\r\
    \n    /interface {\r\
    \n        :set runningRestartEther0 1\r\
    \n        :local o [find name=\"ether0\"]\r\
    \n        set \$o disabled=yes\r\
    \n        :delay 5\r\
    \n        set \$o disabled=no\r\
    \n        :delay 2\r\
    \n        :set runningRestartEther0 0\r\
    \n    }\r\
    \n}\r\
    \n"
/system scheduler
add name="Restart ether0" on-event="Restart ether0" \
    start-date=jan/01/1970 start-time=00:00:00 interval=2s
/tool netwatch
add host=1.1.1.1 \
    down-script="/system scheduler set [find name=\"Restart ether0\"] disabled=no" \
    up-script="/system scheduler set [find name=\"Restart ether0\"] disabled=yes"