Storage Space

Get Messages About Storage Space

A shell script that reports potential storage issues

There are many types of servers in which storage space needs to be watched carefully. Now you can get that information in text messages. Let’s start with a df command:

df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            487M     0  487M   0% /dev
tmpfs            99M  6.6M   93M   7% /run
/dev/vda1        25G  2.9G   21G  13% /
tmpfs           495M     0  495M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           495M     0  495M   0% /sys/fs/cgroup
/dev/sda        2.9G  147M  2.6G   6% /srv/prosody/upload
/dev/sdb        976M  530M  379M  59% /mnt/backups
tmpfs            99M     0   99M   0% /run/user/1000

I want to keep an eye on mountpoints that have less than 50% remaining disk space. So, I pipe the output of the df ‑h command into awk, and I get exactly what I am looking for:

df -h | awk '0+$5 >= 50 {print $6 " has only " $4 " of free space."}'
/mnt/backups has only 379M of free space.

Perfect! Now, just make it a script for text messages:

#!/bin/bash
. /etc/profile
. /root/.profile

JJ=`df -h | awk '0+$5 >= 50 {print $6 " has only " $4 " of free space."}'`

if [ -z "$JJ" ]; then
  /usr/local/bin/monitor.chat.sh "<EYEGLASSES> There is plenty of free disk space on the app server."
  echo "There is plenty of free disk space on the app server."
else
  KK=`printf  "<EYEGLASSES> App Server Available Disk Space Warning:\n$JJ"`
  /usr/local/bin/monitor.chat.sh "$KK"
  echo "Available Disk space for app server reported."
fi

I want the output of this script just once per day. It has helped me to avoid problems with storage and to plan for the future.

Last modified November 9, 2020