Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
crontab questions
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 803

PostPosted: Tue Dec 11, 2012 12:02 am    Post subject: crontab questions Reply with quote

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
View user's profile Send private message
lxg
Veteran
Veteran


Joined: 12 Nov 2005
Posts: 1019
Location: Aachen, Germany

PostPosted: Tue Dec 11, 2012 11:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 803

PostPosted: Wed Dec 12, 2012 11:50 pm    Post subject: Reply with quote

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
View user's profile Send private message
lxg
Veteran
Veteran


Joined: 12 Nov 2005
Posts: 1019
Location: Aachen, Germany

PostPosted: Thu Dec 13, 2012 4:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 803

PostPosted: Sat Dec 15, 2012 3:49 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum