Wednesday, July 2, 2008

sendmail from cron with Zimbra

Today I've faced the problem of sending admin emails from cron, in a machine with Zimbra installed. Zimbra comes with a Postfix installation so, using a 2nd Postfix( or exim, or sendmail) in parallel with the Zimbra's one, could lead you to dangerous places.
With this in mind I've found a simple and fast way to send emails without the needs to touch any system configuration.
Supposing that you want to launch the "ls /" command with the root user, you can write this line:
* * * * * root (echo "Subject: Cron ls /";echo;ls /) | /opt/zimbra/postfix/sbin/sendmail

Within round brackets there's the subject, followed by the output of the command, followed by the recipient.
Simple, fast, secure.