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 admin@zimbrams.com

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

4 comments:

Egor Chel said...

Thanks! Helped me a lot. I had to get command line emailing to work, so I just symlinked sendmail to zimbra's and everything seems to work great so far.

begeto said...

Very clever! Thanks a lot

Jeremy said...

Here's a more in depth look at the issue and symlink fix.

http://ashtech.net/~syntax/blog/archives/124-Cron-Uses-usrsbinsendmail.html

Anonymous said...

Thanks! Great idea. I'm using it for auditing a couple logs.