4

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:

  1. 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.

  2. Using the ~/.forward file. Can't make that work. I suspect it is because this file is really related to sendmail universe and I'm not sure Solaris cron actually uses sendmail 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 ?

3

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 run newaliases.

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):

:0
* ^From: Cron Daemon <unixhacker2010@yourhostname.example.com>
* ^Subject: Cron .*
! otheraddress@otherhost.example.com

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.

… 2>&1 | ifne mailx -s 'Cron output' otheraddress@otherhost.example.com
  • I've accepted this one as an answer. I believe my problems were completely related to having screwed up configuration for sendmail. – unixhacker2010 Jul 26 '13 at 10:17
1

I do not remember that Solaris was that different.

Is there not the /etc/aliases file (might be a different location on Solaris?) where you can simply put a pair from - to?

After that newaliases should activate the change.

  • 1
    Thanks. Can't make that work. I got a suspicion that my underlying problem is that I've somehow messed up my sendmail setup on this particular host. (yes, I'm back to believing that sendmail is involved ... after all). – unixhacker2010 Jul 24 '13 at 21:38
1

The code posted in Solaris cron ignoring mail aliases? could help clarify those for whom this still does not work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.