[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

cronjob in user environment



Hi all,

I want to run a cronjob in a user's environment (i.e. as this user and
not as root).

The script foo.sh to be run by cron on behalf of the a user (johndoe)
needs some env vars (paths) from that user's ~/.bashrc. 

I read about several solutions:

1) use su

If I try in the crontab

    10 12 * * */2   su -p - johndoe -c /home/johndoe/foo.sh

I get the message "su must be run from a terminal" in the cron mail.
Hmm ...

2) define env vars in the crontab

It works if I define the env vars as a full path

    $SOME_VAR=/full/path/1
    $SOME_OTHER_VAR=/full/path/2
    10 12 * * */2   su -p - johndoe -c /home/johndoe/foo.sh

In ~/.bashrc, I have 
    
    $SOME_VAR=$HOME/path/1
    $SOME_OTHER_VAR=$HOME/path/2

and I'd rather not dublicate the definitions.

So, is there another a way to make cron aware of the needed environment?

best,
steve


Reply to: