1

This should be simple, but it doesn't seem to be working. I have a very simple script run by cron:

export [email protected]
[email protected]
echo "MAILTO is set to $MAILTO"

Cron, however, seems to not be picking up the MAILTO variable - the cron e-mails look, in part, like this:

X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/deploy>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=deploy>
Date: Thu, 20 Sep 2012 13:05:01 -0700

MAILTO is set to [email protected]

What am I missing? Why isn't cron picking up the environment variables set in the script?

3 Answers 3

1

A process in Unix can change its own environment variables and can define its children's environment variables when those children are created. A process cannot change its parent's environment variables, those of its children after those children are created, or those of any other process.

It appears as though you're trying to have a cron job change cron's environment variables, which is impossible.

3
  • Uh, ok... so how on earth do I set MAILTO? There seem to be a whole bunch of wrong "tutorials" out there.
    – cbmanica
    Sep 20, 2012 at 20:13
  • @cbmanica: You haven't said why you want to change MAILTO, so I can't tell you how to do it.
    – Gabe
    Sep 20, 2012 at 20:14
  • I thought it was obvious that I wanted the output log e-mails to go someplace other than the owner of the crontab in question.
    – cbmanica
    Sep 20, 2012 at 20:16
0

I'm guessing you're not logged in as the same user the cron is running under. Hence, creating the discrepancy.

0

Set MAILTO environment variable in the crontab file. cron just ignore environment variables for security reason. If MAILTO is not specified, then the output will be mailed to the owner of the process that produced the output.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .