Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[TIP] Dear cron: quit mailing me!
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
NotQuiteSane
Guru
Guru


Joined: 30 Jan 2005
Posts: 488
Location: Klamath Falls, Jefferson, USA, North America, Midgarth

PostPosted: Sun Nov 13, 2005 11:35 pm    Post subject: [TIP] Dear cron: quit mailing me! Reply with quote

I use cron to fetch my mail every 15 minutes. of course, being the nice program it is, it emails me to tell me it worked (or didn't work) that's all fine and dandy, but it's pretty self evident that it did or didn't.

I added the following to my .procmailrc file:

Code:
:0: # No mail from cron about fetchmail
* ^Subject:.cron: fetchmail
/dev/null


a quick check of the log shows it worked:

Code:
From nqs@mike.3dogs.homelinux.net  Sun Nov 13 15:15:26 2005
 Subject: cron: fetchmail --all --nokeep --flush
  Folder: /dev/null


there we go. cron can mail the results, and procmail knows where to put it, and I don't have to see them

NQS
_________________
These opinions are mine, mine I say! Piss off and get your own.

As I see it -- An irregular blog, Improved with new location

To delete French language packs from system use 'sudo rm -fr /'
Back to top
View user's profile Send private message
1U
Guru
Guru


Joined: 21 Jul 2005
Posts: 319

PostPosted: Mon Nov 14, 2005 12:53 am    Post subject: Reply with quote

Thanks for the great tip. Does this apply to those dead.letter files I get after cronning emerge --sync? If so then this will come in handy because those files get quite large after a month of syncing.
Back to top
View user's profile Send private message
NotQuiteSane
Guru
Guru


Joined: 30 Jan 2005
Posts: 488
Location: Klamath Falls, Jefferson, USA, North America, Midgarth

PostPosted: Mon Nov 14, 2005 1:10 am    Post subject: Reply with quote

1U wrote:
Thanks for the great tip. Does this apply to those dead.letter files I get after cronning emerge --sync? If so then this will come in handy because those files get quite large after a month of syncing.


Hmm, I don't think so. I just checked mine, and found at the end a users's password (usually I use password -e so my users can choose their own passwords, but this user is blind, so I manually entered his)!

i've entered
Code:
*/10    *       *       *       *       rm -rf /root/dead.letter


into root's crontab, which will delete the file every 10 minutes. probably need to filter it out, and possibly extend the gap a bit.

NQS
_________________
These opinions are mine, mine I say! Piss off and get your own.

As I see it -- An irregular blog, Improved with new location

To delete French language packs from system use 'sudo rm -fr /'
Back to top
View user's profile Send private message
1U
Guru
Guru


Joined: 21 Jul 2005
Posts: 319

PostPosted: Mon Nov 14, 2005 1:16 am    Post subject: Reply with quote

That's a quick fix, but it would be nice to figure out how to disable mail from cron, in my case completely. I'll have a look later, perhaps it's not so hard.
Back to top
View user's profile Send private message
mr_roboto
n00b
n00b


Joined: 14 Nov 2005
Posts: 4

PostPosted: Mon Nov 14, 2005 2:38 am    Post subject: Reply with quote

thanks great tip :D
_________________
Free Money Click Below
http://rewardhits.com/index.php?hit=2047
Back to top
View user's profile Send private message
Cocker68
Apprentice
Apprentice


Joined: 16 Jan 2003
Posts: 227
Location: Germany

PostPosted: Mon Nov 14, 2005 12:46 pm    Post subject: Reply with quote

1U wrote:
That's a quick fix, but it would be nice to figure out how to disable mail from cron, in my case completely. I'll have a look later, perhaps it's not so hard.

That's easy: cron only sends mail, when there is something to send. Make Your lines in crontab to produce no output, and You won't get mail from that job:
Code:
*    3       *       *       *       /sbin/emerge sync > /dev/null 2>&1


- Cocker :wq
Back to top
View user's profile Send private message
durian
Guru
Guru


Joined: 16 Jul 2003
Posts: 312
Location: Margretetorp

PostPosted: Mon Nov 14, 2005 12:59 pm    Post subject: Reply with quote

1U wrote:
That's a quick fix, but it would be nice to figure out how to disable mail from cron, in my case completely. I'll have a look later, perhaps it's not so hard.


Put
Code:
MAILTO=""
in your crontab

-peter
Back to top
View user's profile Send private message
numerodix
l33t
l33t


Joined: 18 Jul 2002
Posts: 743
Location: nl.eu

PostPosted: Mon Nov 14, 2005 7:53 pm    Post subject: Reply with quote

Cocker68 wrote:
1U wrote:
That's a quick fix, but it would be nice to figure out how to disable mail from cron, in my case completely. I'll have a look later, perhaps it's not so hard.

That's easy: cron only sends mail, when there is something to send. Make Your lines in crontab to produce no output, and You won't get mail from that job:
Code:
*    3       *       *       *       /sbin/emerge sync > /dev/null 2>&1


- Cocker :wq


Or do one of these:

Code:
*    3       *       *       *     /sbin/emerge sync > /dev/null


This way cron will notify you if there was an error, but otherwise keep quiet.
_________________
undvd - ripping dvds should be as simple as unzip
Back to top
View user's profile Send private message
codergeek42
Bodhisattva
Bodhisattva


Joined: 05 Apr 2004
Posts: 5142
Location: Anaheim, CA (USA)

PostPosted: Mon Nov 14, 2005 7:59 pm    Post subject: Reply with quote

Nifty. :) Thanks.
_________________
~~ Peter: Programmer, Mathematician, STEM & Free Software Advocate, Enlightened Agent, Transhumanist, Fedora contributor
Who am I? :: EFF & FSF
Back to top
View user's profile Send private message
1U
Guru
Guru


Joined: 21 Jul 2005
Posts: 319

PostPosted: Tue Nov 15, 2005 3:11 am    Post subject: Reply with quote

Cocker68 wrote:
This way cron will notify you if there was an error, but otherwise keep quiet.

Thank you everyone for all the tips. However I do not understand how cron will notify me of errors if all of the output is piped to /dev/null? Won't the entire output errors or not simply go there? I would appreciate an explanation.
Back to top
View user's profile Send private message
allucid
Veteran
Veteran


Joined: 02 Nov 2002
Posts: 1314
Location: atlanta

PostPosted: Tue Nov 15, 2005 3:32 am    Post subject: Reply with quote

1U wrote:
Cocker68 wrote:
This way cron will notify you if there was an error, but otherwise keep quiet.

Thank you everyone for all the tips. However I do not understand how cron will notify me of errors if all of the output is piped to /dev/null? Won't the entire output errors or not simply go there? I would appreciate an explanation.

If you redirect the output like this:
Code:
*    3       *       *       *     /sbin/emerge sync > /dev/null
Just the output (stdout) gets discarded (note he just used '>'). Errors (stderr) would still be displayed. In the other example above he redirected stdout and stderr both to /dev/null/. See here for a more detailed explanation.

I don't think you want to automatically want to delete dead.letter. AFAIK, dead.letter contains the output that a program (often times this is cron) tried to mail to you but you don't have a mail transfer angent set up so instead it drops everything in dead.letter. This means that it has errors in it that you might care about.
Back to top
View user's profile Send private message
1U
Guru
Guru


Joined: 21 Jul 2005
Posts: 319

PostPosted: Tue Nov 15, 2005 3:44 am    Post subject: Reply with quote

Thank you for the explanation allucid. I just have 3 more questions, sorry for taking this offtopic since it's more about bash than his original tip.

1. That link you pointed to didn't explain >>, I know how to use it but I'm curious how it relates to the others if any relation at all.
2. So as long as I do > /dev/null I can expect to see only errors even from commands as simple as rm in my dead.letter?
3. If I do command1 && command2 && command3 > /dev/null will all of those get properly filtered or not?
Back to top
View user's profile Send private message
NotQuiteSane
Guru
Guru


Joined: 30 Jan 2005
Posts: 488
Location: Klamath Falls, Jefferson, USA, North America, Midgarth

PostPosted: Tue Nov 15, 2005 8:52 am    Post subject: Reply with quote

allucid wrote:
I don't think you want to automatically want to delete dead.letter. AFAIK, dead.letter contains the output that a program (often times this is cron) tried to mail to you but you don't have a mail transfer angent set up so instead it drops everything in dead.letter. This means that it has errors in it that you might care about.


I don't belive this is correct, as in mine I found the text to a letter I sent from the command line. IMO, that is not where it belongs.

NQS
_________________
These opinions are mine, mine I say! Piss off and get your own.

As I see it -- An irregular blog, Improved with new location

To delete French language packs from system use 'sudo rm -fr /'
Back to top
View user's profile Send private message
NotQuiteSane
Guru
Guru


Joined: 30 Jan 2005
Posts: 488
Location: Klamath Falls, Jefferson, USA, North America, Midgarth

PostPosted: Tue Nov 15, 2005 8:55 am    Post subject: Reply with quote

[quote="1U"]Thank you for the explanation allucid. I just have 3 more questions, sorry for taking this offtopic since it's more about bash than his original tip. -/quote]

Not Allucid, but...

Quote:
1. That link you pointed to didn't explain >>, I know how to use it but I'm curious how it relates to the others if any relation at all.


>> = append
> = overwrite

Quote:
3. If I do command1 && command2 && command3 > /dev/null will all of those get properly filtered or not?


No. be cause what you said to do is "do command 1, then if successfull do Command 2, and if it's sucessfull do comand 3 and send it's results to /dev/null

NQS
_________________
These opinions are mine, mine I say! Piss off and get your own.

As I see it -- An irregular blog, Improved with new location

To delete French language packs from system use 'sudo rm -fr /'
Back to top
View user's profile Send private message
allucid
Veteran
Veteran


Joined: 02 Nov 2002
Posts: 1314
Location: atlanta

PostPosted: Tue Nov 15, 2005 5:36 pm    Post subject: Reply with quote

NotQuiteSane wrote:
allucid wrote:
I don't think you want to automatically want to delete dead.letter. AFAIK, dead.letter contains the output that a program (often times this is cron) tried to mail to you but you don't have a mail transfer angent set up so instead it drops everything in dead.letter. This means that it has errors in it that you might care about.


I don't belive this is correct, as in mine I found the text to a letter I sent from the command line. IMO, that is not where it belongs.

NQS

You made me more curious so I googled it:
Quote:
If a letter is found to be undeliverable, it is returned to
the sender with diagnostics that indicate the location and
nature of the failure. If mail is interrupted during input,
the message is saved in the file dead.letter to allow edit-
ing and resending. dead.letter is always appended to, thus
preserving any previous contents. The initial attempt to
append to (or create) dead.letter will be in the current
directory. If this fails, dead.letter will be appended to
(or created in) the user's login directory. If the second
attempt also fails, no dead.letter processing will be done.

So I guess this accounts for both your and my case. In my case cron wasn't able to deliver the mail and in your case your user wasn't able to deliver the mail.
Back to top
View user's profile Send private message
NotQuiteSane
Guru
Guru


Joined: 30 Jan 2005
Posts: 488
Location: Klamath Falls, Jefferson, USA, North America, Midgarth

PostPosted: Fri Nov 18, 2005 3:32 am    Post subject: Reply with quote

allucid wrote:
You made me more curious so I googled it:
Quote:
If a letter is found to be undeliverable, it is returned to
the sender with diagnostics that indicate the location and
nature of the failure. If mail is interrupted during input,
the message is saved in the file dead.letter to allow edit-
ing and resending. dead.letter is always appended to, thus
preserving any previous contents. The initial attempt to
append to (or create) dead.letter will be in the current
directory. If this fails, dead.letter will be appended to
(or created in) the user's login directory. If the second
attempt also fails, no dead.letter processing will be done.

So I guess this accounts for both your and my case. In my case cron wasn't able to deliver the mail and in your case your user wasn't able to deliver the mail.


Again, it doesn't jive. When I sent the letter, I was on the phone with the respondant, and he confirmed getting it almost right away. not more than 2 or 3 minute delay.

most of the time dead.leter doesn't bother me (although i'm curious, need to rtfm, if there is a switch to set the max size). but finding sensitive info in it did. especially since /root is not encrypted

NQS
_________________
These opinions are mine, mine I say! Piss off and get your own.

As I see it -- An irregular blog, Improved with new location

To delete French language packs from system use 'sudo rm -fr /'
Back to top
View user's profile Send private message
jel
Apprentice
Apprentice


Joined: 10 Aug 2005
Posts: 259
Location: Gothenburg

PostPosted: Sat Nov 19, 2005 8:53 pm    Post subject: Reply with quote

1U wrote:

3. If I do command1 && command2 && command3 > /dev/null will all of those get properly filtered or not?


No, for that you need to use brackets:
Code:
(command1 && command2 && command3) > /dev/null


**edit

Somehow I didn't realize you were a nazi scumbag. Fuck you idiot! :-)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks 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