mirror of
https://github.com/guezoloic/serverconfig.git
synced 2026-03-28 18:03:49 +00:00
feat: rework entire repo structure
This commit is contained in:
41
disk-monitor.sh
Normal file
41
disk-monitor.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/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
|
||||
source $ENV_FILE
|
||||
|
||||
INSTALLED=$1
|
||||
if [[ "--install" == $INSTALLED ]]; then
|
||||
log_info "disk-monitor Installation"
|
||||
|
||||
if ! command -v crontab >/dev/null 2>&1; then
|
||||
log_error "Error: crontab not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CRON_JOB="0 3 * * 1 $PROJECT_DIR/disk-monitor.sh"
|
||||
crontab -l | grep -F "$CRON_JOB" > /dev/null 2>&1
|
||||
if ! crontab -l | grep -Fq "$CRON_JOB"; then
|
||||
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -
|
||||
log_success "Cron job added."
|
||||
fi
|
||||
exit 0;
|
||||
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;
|
||||
}'
|
||||
)"
|
||||
Reference in New Issue
Block a user