16.04.2021 – Linux/Send_email_when_disk_reaches_certain_usage.md

Send email when disk reaches certain usage

Frequently run the following script via cron

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/bin/bash

MAX=90
EMAIL=admin@example.com
PART=sda1

USE=`df -h | grep $PART | awk '{ print $5 }' | cut -d'%' -f1`
HOST=`hostname`

if [ $USE -gt $MAX ]; then
  echo "Percent used: $USE" | mail -s "Host $HOST running out of disk space" $EMAIL
fi