View previous topic :: View next topic |
Author |
Message |
grant123 Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
Joined: 23 Mar 2005 Posts: 1080
|
Posted: Tue Dec 11, 2012 12:02 am Post subject: crontab questions |
|
|
My laptop runs a user crontab for root like this:
0 4 * * * layman -S && eix-sync && eix-remote update
15 4 * * * emerge -pvDuN world
20 4 * * * eclean distfiles
30 4 * * * eclean packages
40 4 * * * eix-test-obsolete
45 4 * * * revdep-rebuild -ip
but I'm not getting any mail about it even though ssmtp is working. I do get mail from the crontab on my mail server, but I set 'usermod -c server root' and the mail I get still comes through as:
From: root@example.com (Cron Daemon)
"Cron Daemon" appears in the message list in my mail client but I want it to appear as "server".
Can this crontab be integrated into cronbase or does it have to run as a separate user crontab for root? |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
lxg Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
![](images/avatars/19265729674c9fac4bb9adf.png)
Joined: 12 Nov 2005 Posts: 1019 Location: Aachen, Germany
|
Posted: Tue Dec 11, 2012 11:11 pm Post subject: |
|
|
Ok, you've got a couple of things mixed up here:
1. you have one server where cron doesn't send mail at all.
2. you have another server where mail is sent from the "wrong" sender.
As for 2., please check if the -f and -F options to the ssmtp command can help you. As for 1., please check your MTA's log files, maybe the file got stuck there.
By the way, looking at your crontab entries, you have several commands delayed by a few minutes, presumably to avoid overlapping. This is a bad idea, as this will (a) sometimes not work, and (b) delay things unneccessarily when they would actually go faster.
It would be better to put all the commands into a separate shell file (e.g. /etc/cron.d/my_sys_update.sh) with the following content:
Code: | #!/bin/bash
layman -S && eix-sync && eix-remote update && \
emerge -pvDuN world && \
eclean distfiles && \
eclean packages && \
eix-test-obsolete && \
revdep-rebuild -ip
|
And referencing only this file in the crontab. _________________ lxg.de – codebits and tech talk |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
grant123 Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
Joined: 23 Mar 2005 Posts: 1080
|
Posted: Wed Dec 12, 2012 11:50 pm Post subject: |
|
|
I realized I want to control the subject line as well as the From line. Is there any way to do this with the built-in crontab mail facilities or should I pipe each command's output to mail and set the appropriate parameters there?
Quote: | By the way, looking at your crontab entries, you have several commands delayed by a few minutes, presumably to avoid overlapping. This is a bad idea, as this will (a) sometimes not work, and (b) delay things unneccessarily when they would actually go faster.
It would be better to put all the commands into a separate shell file (e.g. /etc/cron.d/my_sys_update.sh) with the following content: |
Can you tell me more about "sometimes not work"?
The problem with executing everything together like that is I would have to scroll through a lot of stuff to get to the part I want in the email. I could pipe each command to mail separately in the script I suppose. I'm trying that and I don't receive the mail even though I do receive the mail if I execute the command and pipe to mail on the command line. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
lxg Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
![](images/avatars/19265729674c9fac4bb9adf.png)
Joined: 12 Nov 2005 Posts: 1019 Location: Aachen, Germany
|
Posted: Thu Dec 13, 2012 4:09 pm Post subject: |
|
|
grant123 wrote: | Can you tell me more about "sometimes not work"? |
I mean that the approach of inserting a fixed delay will not work. You will almost certainly get overlappings. Not only due to the size of packages to install, but also because the machine may be under stress and everything takes much longer than usuall.
There's another advantage of chaining commands with && – A command will only be exectuted if the previous was successful. (If you don't like this effect, you can still leave commands unchained or seperate them with a semicolon.)
grant123 wrote: | The problem with executing everything together like that is I would have to scroll through a lot of stuff to get to the part I want in the email. I could pipe each command to mail separately in the script I suppose. I'm trying that and I don't receive the mail even though I do receive the mail if I execute the command and pipe to mail on the command line. |
Sure, why not? You could pipe the output to a text file and then pass it to ssmtp. _________________ lxg.de – codebits and tech talk |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
grant123 Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
Joined: 23 Mar 2005 Posts: 1080
|
Posted: Sat Dec 15, 2012 3:49 am Post subject: |
|
|
Thanks, all fixed up. Here's how I'm piping stuff to mailx:
eix-test-obsolete | mail -s "eix-test-obsolete" -a "From: $FROM" $TO |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|