[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to get rid of anacron?



On Mon, 4 Jul 2022 23:39:40 +0300
Roland Mueller <roland.em0001@googlemail.com> wrote:

> > On 7/4/22 10:41, Michael wrote:
> > 
> > afaik systemd timer lack the possibility to send the output (if any)
> > by email to a designated user, but instead logs the output to its
> > journal.
> 
> yes, you are right. If receiving by mail is a requirement - this
> works in cron out of the box.
<SNIP>
> Using systemd scheduler instant check during development is for my
> needs sufficiently covered by 'systemctl status' or journalctl.

There's a trick using a systemd "template" unit that I use to get an
email notification only if something goes wrong.

I have a unit file named email-notify@.service with contents:
    [Unit]
    Description=%i email notification
    
    [Service]
    Type=oneshot
    
    ExecStart=/bin/bash -c '/bin/systemctl status %i | /usr/bin/mail \
    -s "%H: %i $(/bin/systemctl show -p ActiveState --value %i)" root'

Then, in any unit from which I want email notifications on failure, I
add in the [Unit] section the line
OnFailure=email-notify@%n

Then if the primary unit fails, it triggers an instance of email-notify
which has the primary unit's base name as its instance name. Then the
ugly one-liner in email-notify@.service populates the Subject header
with the hostname and the name and status of the failed unit, and the
body with a log summary, and sends it to root.

email-notify@.service is agnostic as to the status of the unit it's
notifying you about, so this doesn't *have* to be limited to on failure
only… That's just how I use it.

Cheers!
 -Chris


Reply to: