Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

share|improve this question

migrated from Sep 21 '12 at 14:41

This question came from our site for professional and enthusiast programmers.

up vote 1 down vote accepted

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.

share|improve this answer
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 '12 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 '12 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 '12 at 20:16

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

share|improve this answer

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.

share|improve this answer

You must log in to answer this question.

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