Monitoring script (Ping, MySQL)

Hi guys - Relatively new to shell programming so please bare with me (I bet everyone says that!)

I'm faced with a problem:

I need a shell script to do the following:

  • Connect to a MySQL database and pull all entrys from the nodes field in a table called 'nodes'
  • These nodes will then be pinged every 2 minutes
  • I need to take the ping response for each node and determine node status (Up or down) and packet loss value and send this back to a database table called 'nodeStatus' with fields node, nodeStatus, and packetLoss.

I need to do this to integrate this into a larger college project. I found a resource online with the following script which pings values from a HOSTS variable and emails on a report but I need to integrate a lot more functionaliy obviously. I'd apreciate if anyone has any pointers / tips on how to do the above.

HOSTS="google.com msn.com"

# no ping request
COUNT=1

# email report when
SUBJECT="Ping failed"
EMAILID="me@mydomain.com"
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

Here is a basic shell script to connect to a mysql db and the results are in the variable $somevar

TABLE_NAME=sometable
USER_NAME=someuser
IP_ADDR=localhost
PASSWORD=somepassword

somevar=`echo "select * from <table_name> where <condition>" | mysql -h $IP_ADDR -u $USER_NAME -p$PASSWD $TABLE_NAME `

echo $somevar