LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Loading env into bash script called by cron (https://www.linuxquestions.org/questions/programming-9/loading-env-into-bash-script-called-by-cron-796412/)

grob115 03-18-2010 11:14 PM

Loading env into bash script called by cron
 
Script programming question for the experts. I have written a bash script that works fine if I execute from the shell interactively. However, once I schedule it to be executed via cron, it just wouldn't work. I believe this has to do with cron running in a different environment than the one I am in when I putty in.

The bash shell script does refer to environment variables in the .cshrc file. I guess these aren't available to the cron? How can I load them into the script if I want them to be available to the cron locally within the script? Thanks!

troop 03-18-2010 11:35 PM

Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.
http://www.unix.com/shell-programmin...file-cron.html

The easiest way you can make sure that you have same environment in cron as you have when running any script as the regular user is to "source" the environment into the script by adding a line like:

. /etc/profile
. /home/user/.profile

to the top of your script (below the #! line).
(c) http://linuxshellaccount.blogspot.co...vironment.html

or just change the #! line to "#!/usr/bin/bash -l"


All times are GMT -5. The time now is 02:11 PM.