2

I am trying to perform a simple check on an integer value output from ping. In Linux this was working quite nicely, but the FreeBSD ping outputs a float value with percentage sign suffixed.

LOSS=`/sbin/ping -c 10 -W 1000 -n $IP | grep loss | awk '{print $7}'`

if [ ${LOSS} > ${LIMIT} ]; then
    # Do something here
fi

But since the value of ${LOSS} is a string, the comparison is failing under BSD.

Help, please?

2 Answers 2

0

You could alter the awk to split on both spaces and dots in order to pull out the integer part of the loss figure.

ping -c 10 1.2.3.4 | grep loss | awk '{FS = " |[\.]"} {print $7}'
0
0

You need to look on the BSDs' ping command. man ping I assume you want de following:

#!/bin/sh

count1=0
count2=0

Ping=$(ping -s 64 10.10.24.6 -c 10 | grep packet | awk '{print $(NF-2)}') # BSD
#Ping=$(ping -s 64 10.10.24.6 -c 10 | grep packet | awk '{print $(NF-4)}')  # Linux

if [ "$Ping" == "0%" ]; then
count1=$((count1 + 1))
echo IP_addr" "UP" "
else
count2=$((count2 + 1))
echo IP_addr" "DOWN" "
fi

echo $count1 IP addresses UP and $count2 IP addresses DOW

In case you don't get the desired result, figure out what parameteres you need to modify in the ping command.

Hope it helps!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .