public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Michael Orlitzky <michael@orlitzky.com>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] crontab questions
Date: Wed, 12 Dec 2012 20:01:30 -0500	[thread overview]
Message-ID: <50C928EA.7000706@orlitzky.com> (raw)
In-Reply-To: <CAN0CFw2nYcPpC-uFh7irZky11ObcGYRBzEYNrFVLFecX_xzx7Q@mail.gmail.com>

On 12/12/2012 05:09 PM, Grant wrote:
>>
>> at roughly the time specified in /etc/crontab. If any of those
>> directories contain scripts, they're run in "alphabetical" order, i.e.
>> how `ls` would sort them.
> 
> Thanks Michael.  I'd like to have more control over when the commands
> are run.  Maybe the system crontab (cronbase) should be used when that
> control isn't necessary or to allow programs to add stuff to a crontab,
> and a user crontab should be used when more control is necessary?
> 

I personally like the idea of the cron.{daily,weekly,...}, but the
implementation is a little goofy. On our mail server, I've added an
additional directory called cron.bihourly to update virus/spam
signatures every two hours. The simplest way to accomplish this is to add,

  # Run every two hours
  0  */2 * * *  root   find -L /etc/cron.bihourly -type f -executable \
                            -execdir '{}' \;

in the global /etc/crontab. I'm sure this is horribly deficient
according to whoever implemented the run-crons stuff, but for me the
additional clarity is worth it.

You can of course add anything else you like in the global/user
crontabs, and they'll work normally.

But be careful: do you really want `emerge -puDN` to run 15 minutes
after you start an `eix-sync`? Or do you just want it to run when
`eix-sync` is done? If it's the latter, you don't want to schedule it 15
minutes later -- you could hit a slow mirror and still be updating when
the `emerge` kicks off. In that case it's better to put all of the
commands in one script, and schedule that when you want. That way the
commands occur in sequence, and you can bail out if something fails.


>> To fix the Subject/From headers, try,
>>
>>   http://www.postfix.org/header_checks.5.html
>>
>> I've never had to use them myself, but I think the REPLACE action will
>> do what you want. The alternative is to replace the sendmail binary with
>> something that executes e.g.,
>>
>>   sed -e 's/Subject: Cron <[^>]> /Subject: /g' | /the/actual/sendmail
>>
>> Both feel a little dirty, but the header checks are less likely to break
>> something assuming that they will work on a client-provided From header.
> 
> I think it's better for me to pipe the commands to mailx.  I get mail if
> I run this on the command line
> 
> emerge -pvDuN world | /usr/bin/mail -s "subject" -a "From: from"
> my@email.com <mailto:my@email.com>
> 
> But I don't get any mail when it runs in the crontab.  Do you know why
> that's happening?  I do get mail from 'emerge -pvDuN world' run in the
> crontab without piping it to mail.

I'm not sure. I do the same thing, though, albeit with a temporary file
(and it works). Maybe try `echo`ing the output to a file? This script
emails me the current iptables to make sure fail2ban hasn't gone berserk:

  #!/bin/bash

  # Send the current iptables -L -n output to the postmaster.

  TMPFILE=/tmp/iptables-state.log
  MAILADDR="postmaster@example.com"

  echo "To: $MAILADDR" > $TMPFILE
  echo "From: root@mx1.example.com" >> $TMPFILE
  echo "Subject: mx1 iptables state" >> $TMPFILE

  iptables -L -n >> $TMPFILE

  sendmail -f root@mx1.example.com \
           $MAILADDR              \
           < $TMPFILE
	
  rm $TMPFILE

It's not very fancy but it does work. If a temp file works for you, it
might help you narrow down the problem.


  reply	other threads:[~2012-12-13  1:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-11 21:15 [gentoo-user] crontab questions Grant
2012-12-12  3:14 ` Michael Orlitzky
2012-12-12 22:09   ` Grant
2012-12-13  1:01     ` Michael Orlitzky [this message]
2012-12-15  2:36       ` Grant
2012-12-15 17:21         ` Michael Orlitzky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50C928EA.7000706@orlitzky.com \
    --to=michael@orlitzky.com \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox