Help needed with mtr script in bash

r00igev@@r

Honorary Master
Joined
Dec 14, 2009
Messages
15,640
Reaction score
14,157
Location
Draadloos Bantha poo doo in 4ways
I have this in a bash variable.
Code:
Start: Mon Mar 22 10:35:42 2021
HOST: intnl-amastelekthreefourtwo                 Loss%   Snt   Last   Avg  Best  Wrst StDev
  1.|-- 10.24.24.2                                   0.0%    20    4.2   4.0   3.5   4.9   0.2
  2.|-- nem1-cust.coolideas.co.za (102.132.201.249)  0.0%    20    4.0   4.2   3.4   5.4   0.2
  3.|-- ???                                         100.0    20    0.0   0.0   0.0   0.0   0.0
  4.|-- ???                                         100.0    20    0.0   0.0   0.0   0.0   0.0
  5.|-- ???                                         100.0    20    0.0   0.0   0.0   0.0   0.0
  6.|-- cloudflare.ixp.joburg (196.60.8.198)         0.0%    20    6.3   8.5   5.6  32.3   7.3
  7.|-- 1.1.1.2                                      0.0%    20    5.1   5.0   4.3   5.4   0.0

How do I create the logic for an if statement to send a webhooks message when the packet loss is not 0.0% or 100.0%?

It seems to be beyond my talent at this stage.
 
I assume you only want to get alerted if the destination has packet loss?

In this case, 1.1.1.2 ?
 
the logic would be so simple but not knowing the number of hops makes it tricky else I'd have run MTR counted n lines and worked from n to 0+2, awk'd the 5th col and done a line by line if or case
 
oh wait wc -l to get # of lines lol

then you know the first two are irrelevant

then proceed as above

can either set to notify if any hop is not within bounds set by check

or if aggregate isn't within the bound

I'm drunk
 
Here's a dirty one all on the same line

Code:
while true; do mtr -r -c10 -o L 1.1.1.1 > test.txt ; loss=($(cat test.txt | awk ' {print $3}' | awk -F. '{ print $1}' | tr -d [a-zA-Z%] )); for hop in "${loss[@]}" ; do if [[ $hop > "0" ]] ; then echo "Packet loss of $hop occured" ;fi; done  ;done

I'd make it nicer but I have work to do :D
 
Top
Sign up to the MyBroadband newsletter
X