Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

Help, please?

share|improve this question
up vote 0 down vote accepted

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 | grep loss | awk '{FS = " |[\.]"} {print $7}'
share|improve this answer

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



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

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

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!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.