Watch

Let’s install on the server msmtp and logwatch, in order to get some notifications about its status.

1. Install msmtp

  1. 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
  2. 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
    EOF
    We assume that we are using a :simple-smtp-server.adoc.
  3. Create the config file /etc/aliases.msmtp, like this:

    FORWARD_ADDRESS="user@gmail.com"
    cat << EOF > /etc/aliases.msmtp
    default: $FORWARD_ADDRESS
    EOF

    All emails from the system will be forwarded to the default address. It can also be a comma separated list of addresses.

  4. Let’s test it:

    mail --help
    mail -s Test1 -- root <<< "Test 1"

2. Install logwatch

  1. Install it:

    apt install --yes logwatch libdate-manip-perl
  2. Create config file /etc/logwatch/conf/logwatch.conf:

    cat <<EOF > /etc/logwatch/conf/logwatch.conf
    Range = between -7 days and -1 days
    EOF

    Run it for the last 7 days.

  3. Make it run weekly, instead of daily:

    mv /etc/cron.daily/00logwatch /etc/cron.weekly/
  4. Test it:

    /etc/cron.weekly/00logwatch