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-13-2011, 06:37 PM
"James B. Byrne"
 
Default use of MAILTO variable in crontab

I want to do something like this:

30 2 * * * MAILTO=testaddr@harte-lyne.ca; echo "this should be mailed"

I have searched extensively and from what I have read I believe that
this should work. But evidently I misapprehend how cron and MAILTO
is supposed to work as my example does not cause any mail to be sent
as far as I can determine from maillog.

How does one specify unique MAILTOs for different cron jobs where
the desired recipient is not the user that runs the cron job?

--
*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:ByrneJB@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-13-2011, 07:03 PM
Michael Best
 
Default use of MAILTO variable in crontab

On 07/13/2011 12:37 PM, James B. Byrne wrote:
> I want to do something like this:
>
> 30 2 * * * MAILTO=testaddr@harte-lyne.ca; echo "this should be mailed"
>
> I have searched extensively and from what I have read I believe that
> this should work. But evidently I misapprehend how cron and MAILTO
> is supposed to work as my example does not cause any mail to be sent
> as far as I can determine from maillog.
>
> How does one specify unique MAILTOs for different cron jobs where
> the desired recipient is not the user that runs the cron job?

Like this:

MAILTO=testaddr@harte-lyne.ca
30 2 * * * echo "this should be mailed"

-Mike
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-13-2011, 07:10 PM
"James B. Byrne"
 
Default use of MAILTO variable in crontab

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?



--
*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:ByrneJB@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-13-2011, 07:26 PM
 
Default use of MAILTO variable in crontab

James B. Byrne 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?

30 2 * * * echo "this should be mailed" | mail -s "important email"
testaddr@harte-lyne.ca

will work.

mark

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-13-2011, 07:30 PM
"Brunner, Brian T."
 
Default use of MAILTO variable in crontab

centos-bounces@centos.org 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?

Note: The script that you trigger (a wrapper for the command you really
want to run) can have the per-command peculiarities in it.
Also: the command in the crontab file can look like 'cmd | mail -s
"Subject of mail" user'
Also: a file (e.g. 'mumble') in the /etc/cron.d directory is effectively
an extension of the /etc/crontab file, and MAILTO can be set there (IIRC
it will only effect entries in that /etc/cron.d/mumble file).


Insert spiffy .sig here:
Life is complex: it has both real and imaginary parts.
Life is not measured by the number of breaths we take, but by the
moments that take our breath away.


//me
************************************************** *****************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom
they are addressed. If you have received this email in error please
notify the system manager. This footnote also confirms that this
email message has been swept for the presence of computer viruses.
www.Hubbell.com - Hubbell Incorporated**

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-13-2011, 07:42 PM
"James B. Byrne"
 
Default use of MAILTO variable in crontab

On Wed Jul 13 15:30:30 EDT 2011, Brunner, Brian T. BBrunner at
gai-tronics.com wrote:
>
> Note: The script that you trigger (a wrapper for the command
> you really want to run) can have the per-command peculiarities
> in it.
> Also: the command in the crontab file can look like 'cmd |
> mail -s "Subject of mail" user'
> Also: a file (e.g. 'mumble') in the /etc/cron.d directory is
> effectively an extension of the /etc/crontab file, and MAILTO
> can be set there (IIRC it will only effect entries in that
> /etc/cron.d/mumble file).

Thanks. I gather from these and previous comments, and from
experimentation, that it is not possible to arbitrarily set the
MAILTO variable in the actual crontab entry. One must set it
somewhere before that entry and, where necessary, reset it to
something else immediately thereafter.

--
*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:ByrneJB@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-13-2011, 09:47 PM
Devin Reade
 
Default use of MAILTO variable in crontab

If you want the output of your cronjob to go to a particular place
that is a bit too inconvenient to do using the built-in functionality,
put a script around your commands and handle the mailing yourself.
This is a good general rule whenever something you want to run from
cron is not trivial (in the sense of its invocation):


#! /bin/sh

MAILTO=somebody@example.com
COMMAND="/usr/local/bin/mycommand"
COMMAND_ARGS="some args"

[ -x $COMMAND ] || exit 0

# safe place for temporary files, including cleanup on exit
TDIR=`mktemp -qtd mycommand.XXXXXXXXXX`
if [ $? -ne 0 ]; then
echo "Failed to create temporary directory; aborted"
exit 1
fi
trap "/bin/rm -rf $TDIR" 0 1 2 15

OUT1=$TDIR/out1
MAIL_OUT=$TDIR/mail-out

# run it
$COMMAND $COMMAND_ARGS 2>&1 > $OUT1

# only mail something out if it produced output. Alternately
# you might want to check the value of $?
if [ -s $OUT1 ]; then

h=`hostname`
cat > $MAIL_OUT <<EOF
To: $MAILTO
Subject: mycommand problem on $h

There is a problem with mycommand on $h. The following is
the output of $COMMAND $COMMAND_ARGS

EOF
cat $OUT >> $MAIL_OUT
/usr/sbin/sendmail -t < $MAIL_OUT
fi

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-14-2011, 04:53 PM
Michael Best
 
Default use of MAILTO variable in crontab

On 07/13/2011 01:10 PM, James B. Byrne 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?

It sets the MAILTO for all entries that follow that MAILTO. You can
have multiple MAILTO entries in your crontab, as well as other variables.

If you only have one or two entries that need non-default mail handling,
you can put them at the end of the crontab.

-Mike
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-14-2011, 05:16 PM
Rudi Ahlers
 
Default use of MAILTO variable in crontab

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"


--
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-14-2011, 05:28 PM
"Mike Burger"
 
Default use of MAILTO variable in crontab

> 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

Visit the Dog Pound II BBS
telnet://dogpound2.citadel.org or http://dogpound2.citadel.org

To be notified of updates to the web site, visit:

https://www.bubbanfriends.org/mailman/listinfo/site-update

or send a blank email message to:

site-update-subscribe@bubbanfriends.org
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 09:28 PM.

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