EDIT: In Openhabian you can also use the integrated MTU. you can activate it in the Openhabian config. Open the config with:
openhabian-config
this will open the config menu.
but I don’t know how configure this integrated MTU… so no support for that in this thread!
Original Post:
I created a little bash script to remind me when the filesystem runs out of space…
Here is the script
#!/bin/bash
EXCLUDE_LIST="<define excluded directories here>|<seperated with | >"
df -H | grep -vE "^Filesystem|tmpfs|cdrom|${EXCLUDE_LIST}" | awk '{print $5 " " $6}' | while read output;
do
echo $output
usage=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usage -ge 90 ]; then
printf "Subject: <your subject here>\n\n$(hostname) is running out of space!\n\nThe actual disk-usage on <your partition name> partition is $usage%%\n\nPlease consider freeing up some diskspace!\n\n$(date)" |
msmtp -d <me@mymail.com>
fi
done
open /etc/cron.daily/ and save a new file with the name memwatchdog.sh:
cd /etc/cron.daily/ && sudo nano memwatchdog.sh
This will open an empty file, paste the script there and edit it!
You can easily customize the script to your needs (edit subject and body)
note:
if [ $usage -ge 90 ]; then
The “90” is the percent of diskusage to start sending alert mails…
After that you will have to setup linux to send mails over smtp, you need your smtp server credentials…
Install mailservice and editor from linux console:
sudo apt install msmtp msmtp-mta mailutils nano
setup msmtp mail:
sudo nano /etc/msmtprc
This will open an empty file (if not confiured)
paste the following and change the settings with your smtp credentials:
# Set default values for all following accounts.
defaults
# Use the mail submission port 587 instead of the SMTP port 25.
port 587
# Always use TLS.
tls on
# Set a list of trusted CAs for TLS. The default is to use system settings, but
# you can select your own file.
tls_trust_file /etc/ssl/certs/ca-certificates.crt
# The SMTP server of your ISP
account <your isp name>
host <your smtp server address e.g. mail.myisp.com>
from <the mailaddress to send mails from e.g. me@mymail.com>
auth on
user <your username>
password <your password>
# Set default account to your isp
account default: <your isp name (must be the same as account name above)>
# Map local users to mail addresses
aliases /etc/aliases
In order to be able to use the mail
command you need to install mailx
additionally:
sudo apt install bsd-mailx
After that configure mailx
to use msmtp
sudo nano /etc/mail.rc
scroll down to the last line and append this:
set mta=/usr/bin/msmtp
now you should be able to send mail from your headless linux system.
Test your configuration with something like:
echo "Subject:Hello World/nThis is my first mail send from my server" | msmtp -d <your email address e.g. me@mymail.com>
or with mail
instead of msmtp
echo "This is my first mail send from my server" | mail -s "Hello World" <your email address e.g. me@mymail.com>
Now open crontab
sudo crontab -e
to automatically start the script add this line at the end:
0 8 * * * /etc/cron.daily/memwatchdog.sh
this will start the script at 8 a.m. every day…
have fun!