crontab environment
Posted
by Adamski
on Server Fault
See other posts from Server Fault
or by Adamski
Published on 2010-02-19T17:27:16Z
Indexed on
2010/04/29
11:47 UTC
Read the original article
Hit count: 318
I have written various scripts to launch Java server applications, which are typically run for 24 hours before being shut down (by invoking the same script with a different parameter).
The script relies on environment variables defined in a file: ~/<user>.env
, which I source from .bashrc
.
This works fine when invoking the script from the command line but if I want to add the script as a crontab entry I run into the problem where .bashrc
isn't read.
My question: What is the best practice approach for solving this problem? I realise I could define a crontab entry such as:
* * * * 1-5 /usr/bin/bash -c '. /home/myuser/myuser.env && /home/myuser/scripts/myscript.sh'
... but this seems plain ugly. Alternatively I could source myuser.env
at the beginning of every script, but this would become a nightmare to maintain.
Any help appreciated.
© Server Fault or respective owner