nix, shell, perl, php, mysql and mac os x tips and tricks

Tuesday, November 10, 2009

Shell script to determine if an IP is pingable

#!/bin/bash

# default host
HOST="10.0.0.1"

# check if there's a host as an argument
if [ $# -eq 1 ]
 then
 HOST=$1
fi

count=$(/sbin/ping -c 1 -t 2 $HOST | /usr/bin/grep 'received' | /sw/bin/awk -F',' '{ print $2 }' | /sw/bin/awk '{ print $1 }') ;
echo "$count"

No comments:

Post a Comment