Like Below Format...
Step-1 First Create a Script..
[root@server ashutosh]# vim ping.sh
--------------------------------------------------------------------------
#!/bin/sh
echo "_____________________________________" >> ping.log
echo " *Ping Status- www.meritnation.com* " >> ping.log
echo "|============ [$(date +%e-%m-%y)] ============|" >> ping.log
echo "_____________________________________" >> ping.log
echo " Name IP Response Rate" >> ping.log
echo " ------ ----- ---------------" >> ping.log
################## Check-Internet ###################
#
for google in google.com
do
ping=$(ping -c 2 "$google" 2>&1| grep "% packet" | cut -d" " -f 6 | tr -d "%")
if [ "$ping" = "" ]
then
echo "Internet $google not valid"
elif [ $ping -eq 100 ]
then
echo "Internet $google Not Responding"
else
echo "Internat $google $((100 - ping))%"
fi
done >> ping.log
################## Check-Server-1 ###################
# Your Server-1 IP
for server1 in 192.168.1.1
do
ping=$(ping -c 2 "$server1" 2>&1| grep "% packet" | cut -d" " -f 6 | tr -d "%")
if [ "$ping" = "" ]
then
echo "Server-1 $server1 not valid"
elif [ $ping -eq 100 ]
then
echo "Server-1 $server1 Not Responding"
else
echo "Serveer-1 $server1 $((100 - ping))%"
fi
done >> ping.log
################## Check-Server-2 ###################
# Your Server-2 IP
for server2 in 192.168.1.2
do
ping=$(ping -c 2 "$server2" 2>&1| grep "% packet" | cut -d" " -f 6 | tr -d "%")
if [ "$ping" = "" ]
then
echo "Server-2 $server2 not valid"
elif [ $ping -eq 100 ]
then
echo "Server-2 $server2 Not Responding"
else
echo "Server-2 $server2 $((100 - ping))%"
fi
done >> ping.log
################## Check-Server-3 ###################
# Your Server-3 IP
for server3 in 192.168.1.3
do
ping=$(ping -c 2 "$server3" 2>&1| grep "% packet" | cut -d" " -f 6 | tr -d "%")
if [ "$ping" = "" ]
then
echo "Server-3 $server3 not valid"
elif [ $ping -eq 100 ]
then
echo "Server-3 $server3 Not Responding"
else
echo "Server-3 $server3 $((100 - ping))%"
fi
done >> ping.log
################## Check-Server-4 ###################
# Your Server-4 IP
for server4 in 192.168.1.4
do
ping=$(ping -c 2 "$server4" 2>&1| grep "% packet" | cut -d" " -f 6 | tr -d "%")
if [ "$ping" = "" ]
then
echo "Server-4 $server4 not valid"
elif [ $ping -eq 100 ]
then
echo "Server-4 $server4 Not Responding"
else
echo "Server-4 $server4 $((100 - ping))%"
fi
done >> ping.log
####################################################
echo "|======= Ping Status Completed =======|" >> ping.log
echo " 100%=OK, 0-99%=Not OK " >> ping.log
echo "|============ [Ashutosh] ============|" >> ping.log
echo "____________________________________" >> ping.log
# Note- Define Your Mail ID and Define Path Log Files Directory....
cat -v ping.log | mutt -s "Ping-Status-www.meritnation.com $(date)" ashutosh.meritnation@gmail.com
mv ping.log /root/Desktop/Script/ping-log/"Status-$(date)"
exit
:wq! (Save & Quit)
--------------------------------------------------------------------------
Step-2 Create Directory...
[root@server ashutosh]# mkdir -p /root/Desktop/Script/ping-log/
Note- This Directory Store ..The Daily Ping Status Log File.
Step-3 Set Execute Permission..
[root@server ashutosh]# chmod +x ping.sh
Step-4 Now Open and define in Crontab file...
Note-
Crontab-: An experienced Linux sysadmin knows the importance of running the routine maintenance jobs in the background automatically.
[root@server ashutosh]# pwd
/home/ashutosh
[root@server ashutosh]# crontab -e
30 08 * * * /home/ashutosh/ping.sh
:wq! (Save & Quit)
(30 08 * * *- Means..This script 'ping.sh' automaticaly run 8:30 am daily and then send mail your email id..or you can also change this time)
more about this crontab..
Click..
http://kb.iu.edu/data/afiz.html
Output @Mail
Subject- Ping-Status-www.meritnation.com Wed Apr 30 10:45:48 IST 2014
Mail-
__________________________________
*Ping Status- www.meritnation.com*
|============ [30-04-14] ===========|
_____________________________________
Name IP Response Rate
------ ----- ---------------
Internat google.com 100%
Server-1 192.168.1.1 100%
Server-2 192.168.1.2 100%
Server-3 192.168.1.3 100%
Server-4 192.168.1.4 100%
|======= Ping Status Completed =======|
100%=OK, 0-99%=Not OK
|============ [Ashutosh] ===========|
__________________________________
______________________________________________________________________________________
Step-1 First Create a Script..
[root@server ashutosh]# vim ping.sh
--------------------------------------------------------------------------
#!/bin/sh
echo "_____________________________________" >> ping.log
echo " *Ping Status- www.meritnation.com* " >> ping.log
echo "|============ [$(date +%e-%m-%y)] ============|" >> ping.log
echo "_____________________________________" >> ping.log
echo " Name IP Response Rate" >> ping.log
echo " ------ ----- ---------------" >> ping.log
################## Check-Internet ###################
#
for google in google.com
do
ping=$(ping -c 2 "$google" 2>&1| grep "% packet" | cut -d" " -f 6 | tr -d "%")
if [ "$ping" = "" ]
then
echo "Internet $google not valid"
elif [ $ping -eq 100 ]
then
echo "Internet $google Not Responding"
else
echo "Internat $google $((100 - ping))%"
fi
done >> ping.log
################## Check-Server-1 ###################
# Your Server-1 IP
for server1 in 192.168.1.1
do
ping=$(ping -c 2 "$server1" 2>&1| grep "% packet" | cut -d" " -f 6 | tr -d "%")
if [ "$ping" = "" ]
then
echo "Server-1 $server1 not valid"
elif [ $ping -eq 100 ]
then
echo "Server-1 $server1 Not Responding"
else
echo "Serveer-1 $server1 $((100 - ping))%"
fi
done >> ping.log
################## Check-Server-2 ###################
# Your Server-2 IP
for server2 in 192.168.1.2
do
ping=$(ping -c 2 "$server2" 2>&1| grep "% packet" | cut -d" " -f 6 | tr -d "%")
if [ "$ping" = "" ]
then
echo "Server-2 $server2 not valid"
elif [ $ping -eq 100 ]
then
echo "Server-2 $server2 Not Responding"
else
echo "Server-2 $server2 $((100 - ping))%"
fi
done >> ping.log
################## Check-Server-3 ###################
# Your Server-3 IP
for server3 in 192.168.1.3
do
ping=$(ping -c 2 "$server3" 2>&1| grep "% packet" | cut -d" " -f 6 | tr -d "%")
if [ "$ping" = "" ]
then
echo "Server-3 $server3 not valid"
elif [ $ping -eq 100 ]
then
echo "Server-3 $server3 Not Responding"
else
echo "Server-3 $server3 $((100 - ping))%"
fi
done >> ping.log
################## Check-Server-4 ###################
# Your Server-4 IP
for server4 in 192.168.1.4
do
ping=$(ping -c 2 "$server4" 2>&1| grep "% packet" | cut -d" " -f 6 | tr -d "%")
if [ "$ping" = "" ]
then
echo "Server-4 $server4 not valid"
elif [ $ping -eq 100 ]
then
echo "Server-4 $server4 Not Responding"
else
echo "Server-4 $server4 $((100 - ping))%"
fi
done >> ping.log
####################################################
echo "|======= Ping Status Completed =======|" >> ping.log
echo " 100%=OK, 0-99%=Not OK " >> ping.log
echo "|============ [Ashutosh] ============|" >> ping.log
echo "____________________________________" >> ping.log
# Note- Define Your Mail ID and Define Path Log Files Directory....
cat -v ping.log | mutt -s "Ping-Status-www.meritnation.com $(date)" ashutosh.meritnation@gmail.com
mv ping.log /root/Desktop/Script/ping-log/"Status-$(date)"
exit
:wq! (Save & Quit)
--------------------------------------------------------------------------
Step-2 Create Directory...
[root@server ashutosh]# mkdir -p /root/Desktop/Script/ping-log/
Note- This Directory Store ..The Daily Ping Status Log File.
Step-3 Set Execute Permission..
[root@server ashutosh]# chmod +x ping.sh
Step-4 Now Open and define in Crontab file...
Note-
Crontab-: An experienced Linux sysadmin knows the importance of running the routine maintenance jobs in the background automatically.
[root@server ashutosh]# pwd
/home/ashutosh
[root@server ashutosh]# crontab -e
30 08 * * * /home/ashutosh/ping.sh
:wq! (Save & Quit)
(30 08 * * *- Means..This script 'ping.sh' automaticaly run 8:30 am daily and then send mail your email id..or you can also change this time)
more about this crontab..
Click..
http://kb.iu.edu/data/afiz.html
Output @Mail
Subject- Ping-Status-www.meritnation.com Wed Apr 30 10:45:48 IST 2014
Mail-
__________________________________
*Ping Status- www.meritnation.com*
|============ [30-04-14] ===========|
_____________________________________
Name IP Response Rate
------ ----- ---------------
Internat google.com 100%
Server-1 192.168.1.1 100%
Server-2 192.168.1.2 100%
Server-3 192.168.1.3 100%
Server-4 192.168.1.4 100%
|======= Ping Status Completed =======|
100%=OK, 0-99%=Not OK
|============ [Ashutosh] ===========|
__________________________________
______________________________________________________________________________________