Monitorer l’espace disk avec un script Shell


louis MARTINBRANDA
Monitorer l’espace disk avec un script...

Ceci est script qui vous permet de monitorer l’espace disque de votre serveur, si ce dernier depasse la limite d’alerte, un mail vous sera automatiquement envoyé.

#!/bin/sh
# This script is licensed under GNU GPL version 2.0 or above
#
# set admin email so that you can get email
ADMIN="your@email.com"
# alert level 90% is default
ALERT=90
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
  #echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge $ALERT ]; then
    echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep" $ADMIN
  fi
done

 

 

Show Comments (0)

Comments

Subscribe to MARTINBRANDA

Subscribe to our email newsletter to receive useful articles and special offers.

We won't share your email address.