Improving the Disk Alert BASH Script

in #bloglast month

A few days ago, I shared the BASH script to alert the high usage of Disk at server. I am slightly adding a usage in GB so that you know the exact amount of HDD apart from the disk percentage.

#!/bin/bash

usage=`df -h / | tail -1 | awk '{print $5}'`
usage=${usage%?}
remaining=`df -h / | tail -1 | awk '{print $4}'`

threshold=95

if [[ $usage -gt $threshold ]]; then
    echo "Diskspace: $usage% (Remaining $remaining) Exceeding $threshold%"
    php /var/www/mail.php "Your Server $(echo $HOSTNAME) Diskspace: $usage% (Remaining $remaining) Exceeding $threshold% $(date)"
    exit 1
else
    echo "Diskspace: $usage% - Remaining $remaining"
    exit 0
fi

image.png

image.png

See this post

Steem to the Moon🚀!

Sort:  

!ask how to alarm on high cpu usage on linux?

See this post

command: !ask is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!.
!ask is currently based on ChatGPT-3.5

Coin Marketplace

STEEM 0.18
TRX 0.14
JST 0.030
BTC 58639.60
ETH 3167.30
USDT 1.00
SBD 2.43