Sunday, April 27, 2008

Testing Connectivity with fping

You can read list of targets (hosts / servers) from a file. The -f option can only be used by the root user. Regular users should pipe in the file via I/O redirectors (stdin). For example:
$ fping < ~/.ping.conf

You can also netmask to ping the entire network i.e generate a target list from a supplied IP netmask. For example, ping the class C 192.168.1.x:
$ fping -g # or
$ fping -g

# Send email if host is down

HOSTS="router sun printer laptop sony-laptop xbox backup-server"
for h in $HOSTS
fping -u $h >& /dev/null
if [ $? -ne 0 ]; then
echo ${h} host is down send email
# mail -s "Host ${h} down"

# Perform an action only on hosts that are currently reachable.

$myHosts = ‘cat /etc/hosts.backup | fping -a‘;
foreach $host (split(/\n/,$myHosts)) {
# take action or call other function

No comments: