Script for Proxmox LXC/VM (and other servers) which sends you an email if a disk runs out of free space
Go to file
Manuel Kamper 842ce45fc4 Readme.md aktualisiert 2023-12-28 18:31:17 +00:00
Readme.md Readme.md aktualisiert 2023-12-28 18:31:17 +00:00

Readme.md

Script for mail notification on servers when disk space is running low

Disclaimer

This Instruction was generated by AI, running a selfhosted LocalAI. So please doublecheck before you use it.

Instructions

To receive notifications when your disk space on your Ubuntu server is running low, you can use the df command to monitor disk usage and set up alerts using the mail command. Here's how you can do it:

Install the mailutils package if it's not already installed on your server:

sudo apt-get install mailutils

Create a script to send an email notification when disk space is low:

#!/bin/bash

# Set your email address here
email="you@example.com"

# Set the threshold for low disk space (in percentage)
threshold=90

# Get the current disk usage
df -h / | awk '$NF > "{{threshold}}%" {print $1}' | while read disk; do
    # Check if the disk usage is above the threshold
    if [ "$disk" -gt "$threshold" ]; then
        # Send an email notification
        echo "Disk $disk is full!" | mail -s "Disk Full Alert" $email
    fi
done

Save the script as disk_full_alert.sh and make it executable:

chmod +x disk_full_alert.sh

Set up a cron job to run the script daily:

sudo crontab -e

Add the following line to the crontab file:

0 */4 * * * /path/to/disk_full_alert.sh This will run the script at 0 minutes past every 4 hours every day.

Now, the script will run every 4 hours, checking disk usage and sending an email notification if the disk space is running low. You can adjust the interval as needed to suit your schedule.

Now, you should receive an email notification when the disk space on your server is running low. You can adjust the threshold variable in the script to set the disk usage percentage at which you want to receive notifications.