Created
June 12, 2021 09:33
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!/bin/bash | |
# Pourcentage du seuil d'espace disque | |
THRESHOLD=80 | |
EMAIL="[email protected]" | |
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