Community discussions

MikroTik App
 
matiasvidoni
just joined
Topic Author
Posts: 13
Joined: Wed Jun 13, 2007 2:24 pm
Location: Llambi Campbell, Argentina
Contact:

Script to disable, wait some seconds and enable an interface

Fri Aug 24, 2012 2:04 pm

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
 
nmaton
Frequent Visitor
Frequent Visitor
Posts: 72
Joined: Fri Feb 18, 2011 12:31 am

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

Fri Aug 24, 2012 4:05 pm

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??
 
matiasvidoni
just joined
Topic Author
Posts: 13
Joined: Wed Jun 13, 2007 2:24 pm
Location: Llambi Campbell, Argentina
Contact:

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

Fri Aug 24, 2012 5:26 pm

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 :)
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

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

Fri Aug 24, 2012 5:53 pm

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.
 
Ivoshiee
Member
Member
Posts: 483
Joined: Sat May 06, 2006 4:11 pm

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

Fri Aug 24, 2012 10:11 pm

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
 
psamsig
Member Candidate
Member Candidate
Posts: 161
Joined: Sun Dec 06, 2009 1:36 pm
Location: Denmark

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

Fri Aug 24, 2012 10:41 pm

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"

Who is online

Users browsing this forum: No registered users and 14 guests