#!/bin/bash # Usage: "Linux - Disk usage monitor.sh" # # Description: # This script is used from inside of Tactical RMM instances to check the Disk usage. # This script should be deployed as a check script. # # Options: # n/a # # Author: D. de Kooker (info@dcomputers.nl) # Sources: https://www.activexperts.com/support/network-monitor/online/linux/ # Changelog : # 27-06-2022 - Initial script from source, tweaked for my environment #set value to percent threshold to monitor VALUE=90 #parse disk usage percentages OUTCODE=0 declare -i OUTCODE for line in $(df -hP | egrep '^/dev/[^loop]' | awk '{ print $1 "_:_" $5 }') do FILESYSTEM=$(echo "$line" | awk -F"_:_" '{ print $1 }') DISK_USAGE=$(echo "$line" | awk -F"_:_" '{ print $2 }' | cut -d'%' -f1 ) if [ $DISK_USAGE -ge $VALUE ]; then echo -e "Disk Usage Alert: Needs Attention!" "A disk is using $DISK_USAGE% greater than threshold $VALUE%" df -hP OUTCODE+=1 else echo "Disk usage okay." fi done if [ $OUTCODE -gt 0 ]; then exit 1 else exit 0 fi