linux - How to send email and store log file from a single cronjob? -
i have cronjob:
* * * * * root echo 'blabla'
it easy 1 :)
now, send email when cronjob done, store log in log file.
i tryed this:
* * * * * root echo 'blabla' | mail -s "cron report" test@example.com > /test/test.log 2>&1
the email sent , test.log file created, test.log file empty.
any idea why?
this because redirecting output of echo
mail
there nothing write log file. result, log file empty.
if want write output of echo
log file , send mail
, use tee
shown below:
echo 'blabla' 2>&1 | tee /test/test.log | mail -s "cron report" test@example.com
Comments
Post a Comment