Managing cron and similar E-Mails from headless systems

Chris Green cl at isbd.net
Fri Feb 17 12:14:06 UTC 2017


On Fri, Feb 17, 2017 at 11:37:10AM +0000, David Fletcher wrote:
> On Fri, 2017-02-17 at 11:14 +0000, Chris Green wrote:
> > I have several headless systems doing useful work around the place:-
> > 
> >     A Raspberry Pi providing local DNS and DHCP
> > 
> >     A Beaglebone Black on our boat monitoring temperatures and
> > batteries
> > 
> >     An old desktop doing backups in the garage
> > 
> >     etc.
> > 
> > 
> > Most of these have one or more cron jobs running periodic rsync
> > backups, copying data, etc.  If the cron job has an error then it
> > sends E-Mail to the owner of the job ('chris' in most cases, might be
> > root in a couple).
> > 
> > It's (moderately) easy to set up an MTA and /etc/aliases so that the
> > messages are sent to my normal E-Mail.  However I can't come up with
> > a
> > straightforward way of indicating where the messsage is *from*.
> > 
> > You can't just invent a domain name for the headless system because
> > that gets the E-Mail rejected by intermediate systems that try and
> > look up the sender host name.  Cron doesn't seem to have any
> > mechanism
> > for setting the sender's name, cron errors just come from 'root@'.
> > 
> > Can anyone suggest a neat way of handling this so that I know where
> > the errors are coming from?
> > 
> > -- 
> > Chris Green
> > 
> 
> Hi Chris,
> Here is a snippet of code that's part of a reminders by email
> application that's been running on my home server for some years.
> The application is kicked off by a cron job on behalf of a user like
> so:-
> 0 3 * * * dave DFReminder
> Perhaps it will help solve your problem?
> 
> strcpy(SendEmailBuf, "sendEmail -q -f ");
> strdncat(SendEmailBuf, Settings.ReturnEmailFrom(), SENDEMAIL_BUF_LEN);
> strdncat(SendEmailBuf, (char *)" -t ", SENDEMAIL_BUF_LEN);
> strdncat(SendEmailBuf, Settings.ReturnEmailTo(), SENDEMAIL_BUF_LEN);
> strdncat(SendEmailBuf, (char *)" -u \"", SENDEMAIL_BUF_LEN);
> strdncat(SendEmailBuf, Dates.ReturnReminderTextPointer(),
> SENDEMAIL_BUF_LEN);
> strdncat(SendEmailBuf, (char *)"\"", SENDEMAIL_BUF_LEN);
> 
> strdncat(SendEmailBuf, (char *)" -m Repeating reminder",
> SENDEMAIL_BUF_LEN);
> 
> system(SendEmailBuf);
> 
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.

If *your* '0 3 * * * dave DFReminder' cron job fails and it sends you
an E-Mail will be able to work out where it came from?  

My issue is that I have several (some remote) systems running cron
jobs like this and I need to be able to work out where a message came
from.


-- 
Chris Green



More information about the ubuntu-users mailing list