Managing cron and similar E-Mails from headless systems

Chris Green cl at isbd.net
Fri Feb 17 13:35:01 UTC 2017


On Fri, Feb 17, 2017 at 06:50:25AM -0600, W Scott Lockwood III wrote:
>    On Feb 17, 2017 06:39, "Chris Green" <[1]cl at isbd.net> wrote:
> 
>      On Fri, Feb 17, 2017 at 06:24:10AM -0600, W Scott Lockwood III
>      wrote:
> 
>    >    On Feb 17, 2017 06:14, "Chris Green" <[1][2]cl at isbd.net> wrote:
>    >
>    >      No use, I want an *ordinary* cron job to identify itself.
>    >      E.g. I have backup jobs running on one of my headless computers
>    with
>    >      cron entries like:-
>    >          20 1 * * * rsync -a --exclude '*.pyc' /home/chris/
>    >      isbd.uk:.syncmisc/odin/
>    >      When something goes wrong I want to be able to identify where
>    the
>    >      mail
>    >      from cron came from.
>    >
>    >    Wrap that cron in a script. Have the script echo the identifier of
>    your
>    >    choice before it does anything else.
>    >    echo "This cron is running on Fred, the RPI system providing DNS
>    and
>    >    DHCP. It lives under your couch."
>    >    Or something similar.
>    >
> 
>      I suppose one could do that, but I don't want E-Mails *except* when
>      there's an error which would make the wrapper script rather
>      complicated.
>      Surely this is a fairly common problem and there must be a
>      reasonably
>      simple solution.
> 
>     But your example cron will send an email with every run as it is now.

No it doesn't.  There will only be an E-Mail from cron when there's
something send to stdout or stderr.  Those rsync commands are silent
unless there's an error.  That's the beauty of the default setup, cron
works silently unless something goes wrong.


>    A wrapper script is no different, except you can further refine it by
>    adding logic to also handle sending email only if there is an error.
>    cron does not do this at all. Yes, you are going to have to write code.
> 
I'd prefer to do it once though (in E-Mail or other configuration)
rather than every time I create a cron job.

-- 
Chris Green



More information about the ubuntu-users mailing list