Re: [gentoo-user] crontab questions
On 12/14/2012 09:36 PM, Grant wrote: I got it working in /etc/crontab. Should I file a bug for http://www.gentoo.org/doc/en/cron-guide.xml to mention that vixie-cron must be restarted when making changes to /etc/crontab? It says: Note that only Vixie-cron schedules jobs in /etc/crontab automatically. You shouldn't have to restart vixie-cron, I think it just scans /etc/crontab every so often. Wouldn't you rather use a one-liner like this? iptables -L -n | mail -s mx1 iptables state -a From: r...@mx1.example.com mailto:r...@mx1.example.com postmas...@example.com mailto:postmas...@example.com Even the simple stuff I like to keep in a separate shell script. They're all under version control so that if one server blows up, all I have to do is checkout the git repo and hit `make` on another box and everything will more-or-less work once I emerge @world. I could avoid using a temp file that way, but it ain't broke so I'm not going to fix it.
Re: [gentoo-user] crontab questions
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. OK, I've moved all of my user crontabs (including root) to /etc/crontab. 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. Done. 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 m...@email.com mailto:m...@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 got it working in /etc/crontab. Should I file a bug for http://www.gentoo.org/doc/en/cron-guide.xml to mention that vixie-cron must be restarted when making changes to /etc/crontab? It says: Note that only Vixie-cron schedules jobs in /etc/crontab automatically. 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=postmas...@example.com echo To: $MAILADDR $TMPFILE echo From: r...@mx1.example.com $TMPFILE echo Subject: mx1 iptables state $TMPFILE iptables -L -n $TMPFILE sendmail -f r...@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. Wouldn't you rather use a one-liner like this? iptables -L -n | mail -s mx1 iptables state -a From: r...@mx1.example.com postmas...@example.com - Grant
Re: [gentoo-user] crontab questions
Is there a way to remove Cron root@hostname from the subject line of crontab mail without piping each cron job to 'mail'? I set 'usermod -c hostname root' on each of my systems so that the From: line displays hostname for crontab mail. This works on each system except the mail server itself which still shows Cron Daemon. Can crontab mail from the mail server be made to display From: hostname like the other systems? I'm not completely clear on how cronbase works. Can this crontab be integrated into the system crontab via cronbase or should it be run as a separate user crontab for root? 0 4 * * * layman -NS eix-sync -n eix-remote update -n 15 4 * * * emerge -pvDuN world 20 4 * * * eclean -C distfiles 30 4 * * * eclean -C packages 40 4 * * * eix-test-obsolete 45 4 * * * revdep-rebuild -ip If your goal is to run these each one after the other, you can simply stick a shell script in /etc/cron.daily that executes them in order. The default crontab runs any executable files in, * /etc/cron.daily * /etc/cron.hourly * /etc/cron.monthly * /etc/cron.weekly 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? 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 m...@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. - Grant
Re: [gentoo-user] crontab questions
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 m...@email.com mailto:m...@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=postmas...@example.com echo To: $MAILADDR $TMPFILE echo From: r...@mx1.example.com $TMPFILE echo Subject: mx1 iptables state $TMPFILE iptables -L -n $TMPFILE sendmail -f r...@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.
[gentoo-user] crontab questions
Is there a way to remove Cron root@hostname from the subject line of crontab mail without piping each cron job to 'mail'? I set 'usermod -c hostname root' on each of my systems so that the From: line displays hostname for crontab mail. This works on each system except the mail server itself which still shows Cron Daemon. Can crontab mail from the mail server be made to display From: hostname like the other systems? I'm not completely clear on how cronbase works. Can this crontab be integrated into the system crontab via cronbase or should it be run as a separate user crontab for root? 0 4 * * * layman -NS eix-sync -n eix-remote update -n 15 4 * * * emerge -pvDuN world 20 4 * * * eclean -C distfiles 30 4 * * * eclean -C packages 40 4 * * * eix-test-obsolete 45 4 * * * revdep-rebuild -ip - Grant
Re: [gentoo-user] crontab questions
On 12/11/2012 04:15 PM, Grant wrote: Is there a way to remove Cron root@hostname from the subject line of crontab mail without piping each cron job to 'mail'? I set 'usermod -c hostname root' on each of my systems so that the From: line displays hostname for crontab mail. This works on each system except the mail server itself which still shows Cron Daemon. Can crontab mail from the mail server be made to display From: hostname like the other systems? I'm not completely clear on how cronbase works. Can this crontab be integrated into the system crontab via cronbase or should it be run as a separate user crontab for root? 0 4 * * * layman -NS eix-sync -n eix-remote update -n 15 4 * * * emerge -pvDuN world 20 4 * * * eclean -C distfiles 30 4 * * * eclean -C packages 40 4 * * * eix-test-obsolete 45 4 * * * revdep-rebuild -ip If your goal is to run these each one after the other, you can simply stick a shell script in /etc/cron.daily that executes them in order. The default crontab runs any executable files in, * /etc/cron.daily * /etc/cron.hourly * /etc/cron.monthly * /etc/cron.weekly 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. 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.