fping is one my favorite network profiling / scripting tool. It uses the Internet Control Message Protocol (ICMP) echo request to determine if a target host is responding or not.
Unlike ping , fping is meant to be used in scripts, so its output is designed to be easy to parse.
You can easily write perl / shell script to check a list of hosts and send mail if any are unreachable.
fping command example
Just type the following command to see if we can reach to router:
$ fping router
Output:
router is alive
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 read all host names from ~/.ping.conf file
$ 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 192.168.1.0/24
or
$ fping -g 192.168.1.0 192.168.1.255
Sample shell script to send email if host is down
#!/bin/bash
HOSTS="router sun printer laptop sony-laptop xbox backup-server"
DLIST=""
for h in $HOSTS
do
fping -u $h >& /dev/null
if [ $? -ne 0 ]; then
echo ${h} host is down send email
# mail -s "Host ${h} down" admin@you.com </dev/null
fi
doneAnother good example is when you want to perform an action only on hosts that are currently reachable.
#!/usr/bin/perl
$myHosts = ‘cat /etc/hosts.backup | fping -a‘;
foreach $host (split(/\n/,$myHosts)) {
# take action or call other function
} You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop














{ 7 comments… read them below or add one }
It’s good tool but it is not in-built in redhat.
[root@server1 scripts]# fping
-bash: fping: command not found
[
from where can I download.
@Rishi, Download FPING RHEL / CentOS / Fedora Package -
http://dag.wieers.com/rpm/packages/fping/
Show us an example of your ping.conf file contents.
cat ping.conf
Hi Vivek,
First of all, thank you for all of the great nix guides which you have posted. I use them all the time.
So I am a somewhat new network admin and I am administering some Fedora 16 boxes. I really like your script here, so I have put it on my testing server (which I use for testing new scripts and software before putting them on the important servers). When I run the script myself, it works perfectly. However, when I run it from crontab, it sends the error emails even though all the hosts I have put into the script are definitely up.
Is there something about crontab which makes this script work differently?
Thanks
Set the full path to binaries i.e. fping command. Also, check your cron log file in /var/log directory.
Vivek,
Using the full path for fping did the trick. Thank you!