0% found this document useful (0 votes)
179 views1 page

Linux Shell Script For Monitoring System Network With Ping Command

This shell script monitors Linux and UNIX systems by pinging specified IP addresses and hostnames. If a ping fails, an email is sent to a designated email address with the subject "Ping failed" and the body containing the hostname that is down and the current date and time. The script defines variables for the hosts to ping, number of ping requests, email subject, and recipient before using ping and mail commands in a for loop to test connectivity and send emails on failures.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
179 views1 page

Linux Shell Script For Monitoring System Network With Ping Command

This shell script monitors Linux and UNIX systems by pinging specified IP addresses and hostnames. If a ping fails, an email is sent to a designated email address with the subject "Ping failed" and the body containing the hostname that is down and the current date and time. The script defines variables for the hosts to ping, number of ping requests, email subject, and recipient before using ping and mail commands in a for loop to test connectivity and send emails on failures.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#!

/bin/bash
# Simple SHELL script for Linux and UNIX system monitoring with
# ping command
# ------------------------------------------------------------------------# Copyright (c) 2006 nixCraft project <http://www.cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# ------------------------------------------------------------------------# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ------------------------------------------------------------------------# Setup email ID below
# See URL for more info:
# http://www.cyberciti.biz/tips/simple-linux-and-unix-system-monitoring-with-pin
g-command-and-scripts.html
# ------------------------------------------------------------------------# add ip / hostname separated by white space
HOSTS="cyberciti.biz theos.in router"
# no ping request
COUNT=1
# email report when
SUBJECT="Ping failed"
EMAILID="[email protected]"
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' |
awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed
echo "Host : $myHost is down (ping failed) at $(date)" | mail -s "$SUBJECT"
$EMAILID
fi
done

You might also like