Reputation: 28454
I've setup crons through cPanel for a long time and the output is always emailed to me. However, I need a cron to run with root permissions and so I added something like this to crontab:
5 0,12,8,20 * * * php /path/to/file.php 2>&1 | mail -s "my cron job" [email protected]
The command executes and I receive an email, but the output is attached as a file ironically named noname
.
How can I get the output to show up in the body of the email instead of in an attached file?
Upvotes: 2
Views: 527
Reputation: 8415
I would highly recommend using mutt
instead
5 0,12,8,20 * * * php /path/to/file.php 2>&1 |mutt -s "your cron job" -- [email protected]
or if you're really set on using whatever your default mail is, possibly use an intermediary file
5 0,12,8,20 * * * php /path/to/file.php 2>&1 /tmp/outfile; mail -s "your cron job" [email protected] < /tmp/outfile; rm -f /tmp/outfile
Upvotes: 0
Reputation: 16116
First can you confirm which mail program you are using and which cron program you are using ? E.g. by default most cron software restricts the PATH, unless you have it set at the top of the crontab.
/bin/mail at least from GNU mailutils doesn't support sending attachments without help from another program (uuencode). /bin/mailx from Heirloom which your system may be using supports attachments, and will happily convert mail sent in non interactive mode that contains illegal byte sequences (non ASCII), from text to an octet stream file attachment as per the Changelog
You can get the output to show up in body instead of attached file by
Upvotes: 1