how to simulate a user's crontab?

John Almberg jalmberg at identry.com
Thu Jul 17 02:12:20 UTC 2008


On Jul 16, 2008, at 10:03 PM, John Almberg wrote:

>>
>> I'm guessing you're having problems with environment settings,  
>> although
>> the vagaries of the question don't give me much to go on (something
>> along the lines of, "when I try to do x in cron, I get the error y;
>> but it works fine when the user runs it outside of cron" would be  
>> more
>> informative.)
>>
>
> Well, this got me thinking and I had to do some playing around to  
> figure out what was wrong...
>
> The difference was that I was testing the command by su-ing into  
> the user, rather than logging in as that user. What I didn't know  
> was su does not change your environment, only permissions (as far  
> as I can tell)
>
> So I was testing with my environment, but crontab was running under  
> the other user's environment.
>
> I always thought that su user and login user were equivalent. Now I  
> know better :-)

Ah! Further digging led me to the - option for su... I am adding this  
note in case anyone else runs into this problem...

Normal su does not change most of your environment... you retain the  
environment you had before typing 'su user'.

However, typing 'su - user' simulates a full login.

Amazing what you can find once you know what to look for!

-- John



More information about the freebsd-questions mailing list