Community discussions

MikroTik App
 
User avatar
mikrotiknetme
just joined
Topic Author
Posts: 6
Joined: Sun Dec 11, 2022 12:12 am

If host is up

Mon Dec 12, 2022 5:33 pm

I'm looking to write a script that checks to see if a host is up (as a boolean) so I can use it in an if statement.
I wrote this but not working :(

:if (string.find([/tool/ping address=192.168.0.5 count=1],"timeout") ) do={ :put "value is false" } else={ :put "value is true" }

:if (:find [/tool/ping address=192.168.0.5 count=1] "timeout" 0 ) do={ :put "value is false" } else={ :put "value is true" }



Also the scripts in netwatch (the 'test' script), are arguments passed into these at all?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: If host is up

Mon Dec 12, 2022 6:50 pm

if (write.at.random true) what do you expect?

:if ([:ping address=192.168.0.5 count=1] = 0) do={
    :put "reply NOT received"
} else={
    :put "reply received"
}
 
User avatar
mikrotiknetme
just joined
Topic Author
Posts: 6
Joined: Sun Dec 11, 2022 12:12 am

Re: If host is up

Tue Dec 13, 2022 3:09 pm

Yes, I got the echos incorrect on my first post as I had copied it, but it still gave the same text if the host was up or down.

Unfortunately, the code you gave does not appear to work either.

[j@MikroTik] > /system script run script1
Columns: SEQ, HOST, SIZE, TTL, TIME
SEQ HOST SIZE TTL TIME
0 1.1.1.1 56 58 25ms735us

reply received
[j@MikroTik] > /system script run script1
Columns: SEQ, HOST, STATUS
SEQ HOST STATUS
0 192.168.192.192 timeout

reply received
[j@MikroTik] >
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: If host is up

Tue Dec 13, 2022 3:38 pm

Why not???

Nex time specify that you use RouterOS v6 or v7...


for v7:
:if ([:typeof ([:ping address=195.168.0.5 count=1 as-value]->"time")] = "nothing") do={
    :put "reply NOT received"
} else={
    :put "reply received"
}
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19099
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: If host is up  [SOLVED]

Tue Dec 13, 2022 4:31 pm

for v7:
:if ([:typeof ([:ping address=shwing count=1 as-value]->"time")] = "nothing") do={
    :put "seed not received"
} else={
    :put "bun in the oven"
}
Fixed it for you, in the spirit of the title! :-)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: If host is up

Tue Dec 13, 2022 4:37 pm

:facepalm: :lol:
 
User avatar
mikrotiknetme
just joined
Topic Author
Posts: 6
Joined: Sun Dec 11, 2022 12:12 am

Re: If host is up

Tue Dec 13, 2022 5:14 pm

Not sure I get your joke :D But thank you for the help
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: If host is up

Tue Dec 13, 2022 5:41 pm

Not sure I get your joke :D But thank you for the help
You really do not noticed that the @anav version is for joke and on my previous post is present the working version???
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19099
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: If host is up

Tue Dec 13, 2022 6:17 pm

I found it amusing, maybe the yolk is on you...... * as in an inseminated egg* lol..............
 
User avatar
mikrotiknetme
just joined
Topic Author
Posts: 6
Joined: Sun Dec 11, 2022 12:12 am

Re: If host is up

Tue Dec 13, 2022 8:43 pm

Really sorry but I can't understand your broken English :D Thanks again for the help

Who is online

Users browsing this forum: BioMax, cdblue and 47 guests