Hi,
i want to create a script which should do the following:
1) ping the remote servers and email the hosts which are down
2) netstat on port x on 2 server and email the result too.
I want both results to be sent in the same email.
I have few ideas but i can't finish it.
Here is my idea:
#!/bin/bash
HOSTS="host1 host2"
# email report
SUBJECT="Ping failed"
EMAILID="
jon@abc.com"
for myHost in $HOSTS
do
jj=$(ping $myHost -w2 | awk '/received/ {print $4}')
if [ $jj -eq 0 ]
then
# 100% failed
echo "Host : $myHost is down (ping failed) at $(date)" | mail -s $SUBJECT" $EMAILID
fi
done
#check netstat
net=$(netstat -na|grep 5005)
if ($net)
then
echo $net
else
ssh host2 $net
echo "The app is running on $HOST and is connected on $net"| mail -s "$SUBJECT" $EMAILID
My issues are:
1) i don't know how to send in one mail both result
2) i don't know how to check the netstat command on if ...then
Many thanks for your help