4

I have a cronjob:

* * * * * root  echo 'blabla'

It is an easy one :)

Now, I would like to send an email when this cronjob is done, but also to store the log in a log file.

I tryed this:

* * * * * root  echo 'blabla'  | mail -s "Cron report" test@example.com  > /test/test.log 2>&1

The email is sent and the test.log file is created, but the test.log file is empty.

Any idea why?

4

1 回答 1

5

This is because you are redirecting the output of echo to mail so there is nothing to write to the log file. As a result, the log file is empty.

If you want to write the output of echo to the log file and also send it to mail, use tee as shown below:

echo 'blabla'  2>&1 | tee /test/test.log | mail -s "Cron report" test@example.com
于 2013-07-22T07:23:21.240 回答