Community discussions

MikroTik App
 
User avatar
nichky
Forum Guru
Forum Guru
Topic Author
Posts: 1275
Joined: Tue Jun 23, 2015 2:35 pm

script-help

Thu Dec 15, 2022 4:07 am

:if ( [/ping 192.x.y.z ] = 0) do={/interface ethernet cable-test ether2 duration=3}

how can i get result on that on the log, rather than waiting on the terminal for this to happen?
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: script-help

Thu Dec 15, 2022 4:30 am

:if ( [/ping 192.x.y.z ] = 0) do={/interface ethernet cable-test ether2 duration=3}

how can i get result on that on the log, rather than waiting on the terminal for this to happen?
You can use /tool/netwatch instead**, then in the "On Down", do something like this:
/log info [/interface ethernet cable-test ether2 duration=3 as-value]

**Not sure your if statement with the ":if [/ping 192.168.88.1]" is correct/works, thus suggesting netwatch since it can periodically do the ping for you (and run your cable test if the down). If you use the ":if ([ping])...", then do={} part is same as above to log the results of cable test.
 
User avatar
nichky
Forum Guru
Forum Guru
Topic Author
Posts: 1275
Joined: Tue Jun 23, 2015 2:35 pm

Re: script-help

Thu Dec 15, 2022 5:29 am

i was thinking something else, but your solutions will do what i am expecting
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: script-help

Thu Dec 15, 2022 6:58 am

I only suggested netwatch since scripting ":ping" isn't so simple. But you can do it, just not a simple "if" since you specify the # of time you want to ping etc. and then have to parse the results. Netwatch wraps that all up for you.

But the basics of using ping is you need an "as-value" to say to return the data (not output to screen) and a count:
:put [/ping 192.168.74.1 as-value count=10]
If really just one ping, in a standalone script, you could do that:
:if ([/ping 192.168.88.1 as-value count=1]->"status" != "timeout") do={
   /log info [/interface ethernet cable-test ether2 duration=3 as-value]
}
But the above get more complex if you care want to take an action if take a long time, or after X number of failed pings, etc. etc.
Last edited by Amm0 on Thu Dec 15, 2022 7:20 am, edited 1 time in total.
 
User avatar
nichky
Forum Guru
Forum Guru
Topic Author
Posts: 1275
Joined: Tue Jun 23, 2015 2:35 pm

Re: script-help

Thu Dec 15, 2022 7:17 am

i think the one above is better, the last one that u posted doesn't work on log:
You do not have the required permissions to view the files attached to this post.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: script-help

Thu Dec 15, 2022 7:20 am

i think the one above is better, the last one that u posted doesn't work on log:
Sorry, the "as-value" is what's important – I was typing it without testing it. I fixed the example above.
/log info [/interface ethernet cable-test ether2 duration=3 as-value]
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: script-help  [SOLVED]

Thu Dec 15, 2022 11:08 am

:if ( [/ping 192.x.y.z ] = 0) do={/interface ethernet cable-test ether2 duration=3}

how can i get result on that on the log, rather than waiting on the terminal for this to happen?

@nichky is for v6 or v7? Syntax change...

On what hardware? ethernet check do not work on same way on all devices...

Why check 3 times and not only "once"? The result is always the last cable check...

for v6
{
    :local tip 192.168.88.1
    :local tif "ether2"
    :if ([:ping address=$tip count=1] = 0) do={
        :local test [/interface ethernet cable-test $tif once as-value]
        :if (($test->"status") = "link-ok") do={
            :log warning "reply from $tip NOT received, but the link on $tif appear to be OK"
        } else={
            :local tcap [:tostr ($test->"cable-pairs")]
            :log warning "reply from $tip NOT received, and there is NO link on $tif [$tcap]"
        }
    } else={
        :log info "reply from $tip received"
    }
}

for v7
{
    :local tip 192.168.88.1
    :local tif "ether2"
    :if ([:typeof ([:ping address=$tip count=1 as-value]->"time")] = "nothing") do={
        :local test [/interface ethernet cable-test $tif once as-value]
        :if (($test->"status") = "link-ok") do={
            :log warning "reply from $tip NOT received, but the link on $tif appear to be OK"
        } else={
            :local tcap [:tostr ($test->"cable-pairs")]
            :log warning "reply from $tip NOT received, and there is NO link on $tif [$tcap]"
        }
    } else={
        :log info "reply from $tip received"
    }
}

both script can be altered, for example, for warn if for 10 ping the reply are less (= unstable), or not reply at all (= ureachable)
 
User avatar
nichky
Forum Guru
Forum Guru
Topic Author
Posts: 1275
Joined: Tue Jun 23, 2015 2:35 pm

Re: script-help

Thu Dec 15, 2022 1:36 pm

three point basket

Who is online

Users browsing this forum: NxtGen [Bot] and 22 guests