mirror of
https://github.com/guezoloic/serverconfig.git
synced 2026-03-28 10:01:07 +00:00
31 lines
1008 B
Bash
31 lines
1008 B
Bash
#!/bin/bash
|
|
|
|
# DISK MONITORING & INSTALLATION SCRIPT
|
|
# This script monitors disk usage and sends notifications.
|
|
# It can also self-install into the system crontab.
|
|
|
|
PROJECT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
readonly PROJECT_DIR 2>/dev/null
|
|
|
|
source $PROJECT_DIR/utils.sh 2>/dev/null
|
|
|
|
INSTALLED=$1
|
|
if [[ "--install" == $INSTALLED ]]; then
|
|
log_info "disk-monitor Installation"
|
|
CMD="0 3 * * 1 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin $PROJECT_DIR/disk-monitor.sh"
|
|
add_crontab "$CMD"
|
|
exit
|
|
fi
|
|
|
|
usage=80
|
|
send_notification "$(
|
|
df -h / | grep / | awk -v max="$usage" '{
|
|
usage = $5;
|
|
gsub("%", "", usage);
|
|
if (usage > max) {
|
|
printf "<b>⚠️ Warning ⚠️:</b>\nDisk usage is at <code>%d%%</code>, which exceeds the threshold of <code>%d%%</code>.\n\n", usage, max;
|
|
}
|
|
printf "<b>💾 Disk Usage Information 💾 :</b>\nTotal: <code>%s</code>, Used: <code>%s</code>, Available: <code>%s</code>\n", $2, $3, $4;
|
|
}'
|
|
)"
|