If a cron job produces output it is e-mailed to the user's account.
I would like to redirect this e-mail to another e-mail account. Preferably on a user-by-user basis.
I've looked into some options that are often mentioned in other postings:
-
Using the cron
MAILTO
variable. Won't work. That one is not
supported on Solaris. It is a Linux thing, potentially also a BSD
thing, but certainly doesn't exist on Solaris. -
Using the
~/.forward
file. Can't make that work. I suspect it is
because this file is really related tosendmail
universe and I'm
not sure Solaris cron actually usessendmail
to send its e-mails.
To get to the bottom of this I guess I need to understand exactly by which mechanism Solaris cron sends e-mails.
Anyone ?
Best Answer
If you want to forward all of a user's mail, not just the mail from Cron, Solaris does support
~/.forward
. Solaris also supports global aliases in/etc/mail/aliases
; if you modify this file, you need to runnewaliases
.If you only want to forward mail from cron, you can set a filter in
~/.forward
or/etc/mail/aliases
. I don't think Solaris comes with any useful filtering tool preinstalled; the classic program for this is procmail. Use|/usr/local/bin/procmail
as your filter, and something like this as your~/.procmailrc
(untested):Alternatively, you can mail the output of the job explicitly from the crontab. Install moreutils (I don't know how easy it is to compile under Solaris), which contains a command
ifne
that executes a program only if its standard input is not empty.