Skip to content

Instantly share code, notes, and snippets.

@mathieuthollet
Created June 12, 2021 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathieuthollet/365f8c1cb3a9218aeff5a3673663f416 to your computer and use it in GitHub Desktop.
Save mathieuthollet/365f8c1cb3a9218aeff5a3673663f416 to your computer and use it in GitHub Desktop.
Vérifie l'espace disque et envoie une alerte par mail au dessus du seul définit.
!/bin/bash
# Pourcentage du seuil d'espace disque
THRESHOLD=80
EMAIL="xxx@xxx.com"
IP=$(ifconfig eth0 | awk '/inet / {print $2}' | cut -d ':' -f2)
date=`date`
iLigne=0
for DF in `df -h |awk {'print $5'}` ; do
((iLigne+=1))
taille=`expr length "$DF"`;
if [ $taille -lt 3 ];
then
DF="0$DF"
fi
if [ $iLigne -gt 1 ] ;
then
if [[ "$DF" > "$THRESHOLD" ]];
then
echo "Alerte envoyé car $DF utilisé"
mail -s "Espace disque a $DF sur $HOSTNAME le $date" $EMAIL << EOF
Espace disque faible sur $HOSTNAME - $IP, actuellement $DF d'espace occupé
EOF
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment