FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 07-14-2011, 05:38 PM
Rudi Ahlers
 
Default use of MAILTO variable in crontab

On Thu, Jul 14, 2011 at 7:28 PM, Mike Burger <mburger@bubbanfriends.org> wrote:
>
>> On Wed, Jul 13, 2011 at 9:10 PM, James B. Byrne <byrnejb@harte-lyne.ca>
>> wrote:
>>>
>>> On Wed Jul 13 15:03:40 EDT 2011, Michael Best mbest at pendragon.org
>>> *wrote:
>>>> Like this:
>>>>
>>>> MAILTO=testaddr at harte-lyne.ca
>>>> 30 2 * * * echo "this should be mailed"
>>>
>>> That sets MAILTO for the entire crontab does it not? *I want to set
>>> MAILTO differently for specific crontab entries. *Is that possible?
>>> How is it done? *Or do I have to pipe stuff to /usr/bin/mail
>>> explicitly?
>>>
>>
>>
>>
>> Easy:
>>
>>
>> MAILTO="root"
>> 30 2 * * * echo "this should be mailed to root"
>> MAILTO="james@harte.x.x"
>> 30 4 * * * echo "this should be mailed to James"
>> MAILTO="bob"
>> 30 5 * * * echo "this should be mailed to Bob"
>> MAILTO=""
>> 30 6 * * * echo "this should be mailed to no-one"
>
> Why not simply do one of the following:
>
> 30 6 * * * /path/to/job 2>&1 | mail -s "<job name> output" user at domain
> .com
>
> Or
>
> Within the script that runs the job, send the output of the to a file,
> then cat the contents of the file through
>
> mail -s "<job name> output" user at domain.com
> --
> Mike Burger
> http://www.bubbanfriends.org



I suppose it depends on which option you prefer


But, I think if your crontab has many lines then it's a bit easier to
use the method I suggested.


For example:

MAILTO="root"
line1
line2
line3
.....
.....
line9


MAILTO="support-dept"
line10
line11
line12
......
......
line13
line14



MAILTO=""
line15
line16
etc

--
Kind Regards
Rudi Ahlers
SoftDux

Website: http://www.SoftDux.com
Technical Blog: http://Blog.SoftDux.com
Office: 087 805 9573
Cell: 082 554 7532
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-15-2011, 09:13 AM
 
Default use of MAILTO variable in crontab

In article <22f345fb082accaea3abb2d0e9db0134.squirrel@www.bub banfriends.org>,
Mike Burger <mburger@bubbanfriends.org> wrote:
>
> > On Wed, Jul 13, 2011 at 9:10 PM, James B. Byrne <byrnejb@harte-lyne.ca>
> > wrote:
> >>
> >> On Wed Jul 13 15:03:40 EDT 2011, Michael Best mbest at pendragon.org
> >> *wrote:
> >>> Like this:
> >>>
> >>> MAILTO=testaddr at harte-lyne.ca
> >>> 30 2 * * * echo "this should be mailed"
> >>
> >> That sets MAILTO for the entire crontab does it not? *I want to set
> >> MAILTO differently for specific crontab entries. *Is that possible?
> >> How is it done? *Or do I have to pipe stuff to /usr/bin/mail
> >> explicitly?
> >>
> > Easy:
> >
> > MAILTO="root"
> > 30 2 * * * echo "this should be mailed to root"
> > MAILTO="james@harte.x.x"
> > 30 4 * * * echo "this should be mailed to James"
> > MAILTO="bob"
> > 30 5 * * * echo "this should be mailed to Bob"
> > MAILTO=""
> > 30 6 * * * echo "this should be mailed to no-one"
>
> Why not simply do one of the following:
>
> 30 6 * * * /path/to/job 2>&1 | mail -s "<job name> output" user at domain
> .com

Because that will generate an email every time the job runs. Doing it
by setting MAILTO in the crontab will only generate an email if the job
produces output. This can be significant if you only want to know when
the job has something to say or encounters a problem.

Cheers
Tony
--
Tony Mountifield
Work: tony@softins.co.uk - http://www.softins.co.uk
Play: tony@mountifield.org - http://tony.mountifield.org
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 11:51 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org