Simplepush Blog

Full disk alert to your Android or iOS phone with Simplepush

Sometimes proper server monitoring is just not worth the effort. However it can still be useful to know when a disk on your server starts to become full.

The following Bash script is perfect for this. All you need is the Simplepush app installed on your Android or iOS device in order to receive the alerts. Since full disk alerts shouldn’t happen too often, the free version of the Simplepush app should be good enough.

Replace YourKey with your Simplepush key that you receive immediately after installing the Simplepush app. You can also change the threshold to adjust the percentage of space that needs to be used up before an alert is triggered.

#!/bin/bash

SIMPLEPUSH_KEY=YourKey
THRESHOLD=90

df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read line;
do
  percentage=$(echo $line | awk '{ print $1}' | cut -d'%' -f1  )
  disk=$(echo $line | awk '{ print $2 }' )
  if [ $percentage -ge $THRESHOLD ]; then
    curl --silent --output /dev/null --data "key=$SIMPLEPUSH_KEY&title=$disk&msg=Disk usage at $percentage%!" https://api.simplepush.io/send
  fi
done

You can also find the bash script here: https://gist.github.com/simplepush/af1b9c87e9203664fbd40b7bb300175a.

You can make this script run once a day by creating a cronjob. Type crontab -e and then append the following line where you adjust the path to the disk monitoring script:

@daily /path/to/disk-monitor.sh

Now you will get a notification once a day for any disk that is at least 90% full.

Share on:
Imprint