Linux Shell Script for Monitoring Server with ping command

Valic —  June 6, 2010 — Leave a comment

I’ll show you a simple script for easily monitor server



#!/bin/bash
# Monitoring Server with ping

########################################################

# host/ip
HOST="debian-tutorials.com"

# NO ping request
COUNT=3

# Report
SUBJECT="Server Down!"
EMAIL="[email protected]"
for host in $HOST

do
count=$(ping -c $COUNT $HOST | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')

  if [ $COUNT -eq 0 ]; then
# Server is DOWN!

    echo "Host : $HOST is down (ping failed) at $(date)" | mail -s "$SUBJECT" $EMAILID
  fi
done

Valic

Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

No Comments

Be the first to start the conversation.

Leave a Reply