Skip to content

Instantly share code, notes, and snippets.

@anjilinux
Forked from tedheich/DiskCheck.sh
Created June 11, 2024 09:27
Show Gist options
  • Save anjilinux/78468ece4df5eeffc9d30a0c7c5a2688 to your computer and use it in GitHub Desktop.
Save anjilinux/78468ece4df5eeffc9d30a0c7c5a2688 to your computer and use it in GitHub Desktop.
How to check disk level in Linux and mail an alert
ADMIN="[email protected]"
# set alert-level 90 % standard
ALERT=10
df -h | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge $ALERT ]; then
echo "space low on \"$partition ($usep%)\", on server $(hostname) at $(date)" |
mail -s "Alert: Free space low, $usep % used on $partition" $ADMIN
fi
done
#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=90
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
mail -s 'Disk Space Alert' [email protected] << EOF
Your root partition remaining free space is critically low. Used: $CURRENT%
EOF
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment