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
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
In article 22f345fb082accaea3abb2d0e9db0134.squirrel@www.bubbanfriends.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