1 |
On 12/12/2012 05:09 PM, Grant wrote: |
2 |
>> |
3 |
>> at roughly the time specified in /etc/crontab. If any of those |
4 |
>> directories contain scripts, they're run in "alphabetical" order, i.e. |
5 |
>> how `ls` would sort them. |
6 |
> |
7 |
> Thanks Michael. I'd like to have more control over when the commands |
8 |
> are run. Maybe the system crontab (cronbase) should be used when that |
9 |
> control isn't necessary or to allow programs to add stuff to a crontab, |
10 |
> and a user crontab should be used when more control is necessary? |
11 |
> |
12 |
|
13 |
I personally like the idea of the cron.{daily,weekly,...}, but the |
14 |
implementation is a little goofy. On our mail server, I've added an |
15 |
additional directory called cron.bihourly to update virus/spam |
16 |
signatures every two hours. The simplest way to accomplish this is to add, |
17 |
|
18 |
# Run every two hours |
19 |
0 */2 * * * root find -L /etc/cron.bihourly -type f -executable \ |
20 |
-execdir '{}' \; |
21 |
|
22 |
in the global /etc/crontab. I'm sure this is horribly deficient |
23 |
according to whoever implemented the run-crons stuff, but for me the |
24 |
additional clarity is worth it. |
25 |
|
26 |
You can of course add anything else you like in the global/user |
27 |
crontabs, and they'll work normally. |
28 |
|
29 |
But be careful: do you really want `emerge -puDN` to run 15 minutes |
30 |
after you start an `eix-sync`? Or do you just want it to run when |
31 |
`eix-sync` is done? If it's the latter, you don't want to schedule it 15 |
32 |
minutes later -- you could hit a slow mirror and still be updating when |
33 |
the `emerge` kicks off. In that case it's better to put all of the |
34 |
commands in one script, and schedule that when you want. That way the |
35 |
commands occur in sequence, and you can bail out if something fails. |
36 |
|
37 |
|
38 |
>> To fix the Subject/From headers, try, |
39 |
>> |
40 |
>> http://www.postfix.org/header_checks.5.html |
41 |
>> |
42 |
>> I've never had to use them myself, but I think the REPLACE action will |
43 |
>> do what you want. The alternative is to replace the sendmail binary with |
44 |
>> something that executes e.g., |
45 |
>> |
46 |
>> sed -e 's/Subject: Cron <[^>]> /Subject: /g' | /the/actual/sendmail |
47 |
>> |
48 |
>> Both feel a little dirty, but the header checks are less likely to break |
49 |
>> something assuming that they will work on a client-provided From header. |
50 |
> |
51 |
> I think it's better for me to pipe the commands to mailx. I get mail if |
52 |
> I run this on the command line |
53 |
> |
54 |
> emerge -pvDuN world | /usr/bin/mail -s "subject" -a "From: from" |
55 |
> my@×××××.com <mailto:my@×××××.com> |
56 |
> |
57 |
> But I don't get any mail when it runs in the crontab. Do you know why |
58 |
> that's happening? I do get mail from 'emerge -pvDuN world' run in the |
59 |
> crontab without piping it to mail. |
60 |
|
61 |
I'm not sure. I do the same thing, though, albeit with a temporary file |
62 |
(and it works). Maybe try `echo`ing the output to a file? This script |
63 |
emails me the current iptables to make sure fail2ban hasn't gone berserk: |
64 |
|
65 |
#!/bin/bash |
66 |
|
67 |
# Send the current iptables -L -n output to the postmaster. |
68 |
|
69 |
TMPFILE=/tmp/iptables-state.log |
70 |
MAILADDR="postmaster@×××××××.com" |
71 |
|
72 |
echo "To: $MAILADDR" > $TMPFILE |
73 |
echo "From: root@×××××××××××.com" >> $TMPFILE |
74 |
echo "Subject: mx1 iptables state" >> $TMPFILE |
75 |
|
76 |
iptables -L -n >> $TMPFILE |
77 |
|
78 |
sendmail -f root@×××××××××××.com \ |
79 |
$MAILADDR \ |
80 |
< $TMPFILE |
81 |
|
82 |
rm $TMPFILE |
83 |
|
84 |
It's not very fancy but it does work. If a temp file works for you, it |
85 |
might help you narrow down the problem. |