Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Activate Script

Tue Mar 29, 2022 11:44 pm

I have the following script and I want it to be activated when I don't have internet and deactivate when I have internet. Thanks for your help.

:global script false;
:do {
/if condition=([/ping 1.1.1.1 count=6] =0) else={:put "if there is internet"}
do={:put "there is no Internet"}
:delay 6;
} while=(!$script)



EL DONCITO.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Activate Script  [SOLVED]

Thu Mar 31, 2022 8:27 am

No need to use ping in script.

What you do is to use netwatch.
There you can have a script for up/down information.

Script name: Netwatch
####################################
# Netwatch script
#
# Used as both up and down script
# Created Jotne 2021 v1.5
#
####################################
:local Host $host
/tool netwatch
:local Status [get [find where host="$Host"] status]
:local Comment [get [find where host="$Host"] comment]
:local Interval [get [find where host="$Host"] interval]
:local Since [get [find where host="$Host"] since]
:log info "script=netwatch watch_host=$Host comment=\"$Comment\" status=$Status interval=$Interval since=\"$Since\""
Then add an IP to monitor like this:
/tool netwatch
add down-script=Netwatch host=8.8.8.8 up-script=Netwatch

See more information here: viewtopic.php?p=888800#p888800
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Activate Script

Thu Mar 31, 2022 8:23 pm

No need to use ping in script.

What you do is to use netwatch.
There you can have a script for up/down information.

Script name: Netwatch
####################################
# Netwatch script
#
# Used as both up and down script
# Created Jotne 2021 v1.5
#
####################################
:local Host $host
/tool netwatch
:local Status [get [find where host="$Host"] status]
:local Comment [get [find where host="$Host"] comment]
:local Interval [get [find where host="$Host"] interval]
:local Since [get [find where host="$Host"] since]
:log info "script=netwatch watch_host=$Host comment=\"$Comment\" status=$Status interval=$Interval since=\"$Since\""
Then add an IP to monitor like this:
/tool netwatch
add down-script=Netwatch host=8.8.8.8 up-script=Netwatch

See more information here: viewtopic.php?p=888800#p888800
Thanks for your answer friend, and how do I store it in a file?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Activate Script

Thu Mar 31, 2022 8:28 pm

Ehm.. what file for what? :shock:
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Activate Script

Thu Mar 31, 2022 8:37 pm

# Netwatch script
:local Host $host
Uh... nice catch @Jotne...
The possibility to use $host inside netwatch is not documented...
Where you find it?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Activate Script

Thu Mar 31, 2022 8:44 pm

Not sure where I get it from. May have seen it some place and start using it.

Who is online

Users browsing this forum: maxslug and 18 guests