Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

export MAILTO=foo@foo.com
MAILTO=foo@foo.com
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 foo@foo.com

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

share|improve this question

migrated from stackoverflow.com Sep 21 '12 at 14:41

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

3 Answers 3

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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