In this recipe, we will use a small script that will monitor the available filesystem's disk space periodically using cron, and if it exceeds a certain percentage threshold the script will send out a mail with a warning message.
To complete this recipe, you will require a working installation of the CentOS 7 operating system with root privileges and a console-based text editor of your choice. You should have read the Scheduling tasks with cron recipe to have a basic understanding of the principles behind the cron system.
To begin this recipe, log in as root and create the following file that will contain our monitoring script:
vi /etc/cron.daily/monitor_disk_space.sh
Now, put in the following content:
#!/bin/bash EMAIL="root@localhost" THRESHOLD=70 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...