views:

921

answers:

5

I know that default cron's behavior is to send normal and error output to cron's owner local email box.

Is there other ways to get theses results (for example to send it by email to a bunch of people, to store them somewhere, and so on) ?

+5  A: 

The cron line is just like any other unix command line so you can redirect output to another program. Ie.

* * * * * /path/my/command > /my/email/script 2&>1
Vagnerr
I think you meant | instead of >. Using > will write the output to the file.
bmb
A: 

You could chuck file redirection onto either the command shown or the actual command in the crontab for both stdout and stderr - like command > /tmp/log.txt 2>&1 .

If you want several users to receive this log, you could insert a MAILTO=nameofmailinglist at the top of you cron file.

Espo
A: 

This may be an unnecessary addition, but to qualify the redirection commands:

> redirects standard output

2 is a Bourne shell specific term that means standard error

1 is a Bourne shell specific term that means standard output

2>&1 means redirect the standard error to standard output

Also see the following useful article Standard Input and Output Redirection

David
2 and 1 aren't just Bourne shell specific.
Rob Wells
Rob Wells
+4  A: 

To email the output to a different email address just add the line

MAILTO="[email protected]"

To the crontab before the command

Rodney Amato
A: 

As far as I see it you've got three options:

  1. Redirect the output: either to a file, or to a program that will email the results as you want them

  2. Use MAILTO in cron, and redirect the email to any other single address for all your cron jobs.

  3. Do the redirection in your mail server or client, after cron has sent it.

Douglas Leeder