Readme.md hinzugefügt

This commit is contained in:
Manuel Kamper 2023-12-28 17:38:51 +00:00
commit c5425aa9db
1 changed files with 51 additions and 0 deletions

51
Readme.md Normal file
View File

@ -0,0 +1,51 @@
# Script for mail notofication on servers when disk space is running low
## Disclaimer
This 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. Heres how you can do it:
Install the mailutils package if its not already installed on your server:
´sudo apt-get install mailutils´
Create a script to send an email notification when disk space is low:
Copy code
#!/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:
Copy code
chmod +x disk_full_alert.sh
Set up a cron job to run the script daily:
Copy code
sudo crontab -e
Add the following line to the crontab file:
Copy code
0 0 * * * /path/to/disk_full_alert.sh
This will run the script at midnight every day.
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.