Watch
Let’s install on the server msmtp and logwatch, in order
to get some notifications about its status.
1. Install msmtp
-
Let’s make sure first that we have the right packages installed:
apt purge --yes mailutils mailutils-common apt autoremove --yes apt install --yes msmtp msmtp-mta bsd-mailx -
Create the config file
/etc/msmtprc:MAIL_DOMAIN="notify.example.org" MAIL_HOST="smtp.${MAIL_DOMAIN}" MAIL_FROM="$(hostname)@${MAIL_DOMAIN}" cat <<EOF > /etc/msmtprc account smtp maildomain $MAIL_DOMAIN host $MAIL_HOST from $MAIL_FROM tls_starttls on set_from_header on account default : smtp aliases /etc/aliases.msmtp syslog LOG_MAIL EOFWe assume that we are using a :simple-smtp-server.adoc. -
Create the config file
/etc/aliases.msmtp, like this:FORWARD_ADDRESS="user@gmail.com" cat << EOF > /etc/aliases.msmtp default: $FORWARD_ADDRESS EOFAll emails from the system will be forwarded to the default address. It can also be a comma separated list of addresses.
-
Let’s test it:
mail --help mail -s Test1 -- root <<< "Test 1"
2. Install logwatch
-
Install it:
apt install --yes logwatch libdate-manip-perl -
Create config file
/etc/logwatch/conf/logwatch.conf:cat <<EOF > /etc/logwatch/conf/logwatch.conf Range = between -7 days and -1 days EOFRun it for the last 7 days.
-
Make it run weekly, instead of daily:
mv /etc/cron.daily/00logwatch /etc/cron.weekly/ -
Test it:
/etc/cron.weekly/00logwatch