Question

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) ?

Was it helpful?

Solution

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.

OTHER TIPS

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

MAILTO="user@example.com"

To the crontab before the command

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

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

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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top