1

This question already has an answer here:

I have an entry in cron.d:

31 17 * * * root /home/some_user/.bash_profile; /home/some_user/bin/some_script

The profile sets a specific path, and I echo the current path in the profile to ensure its correct. But, when the script executes, a command in it fails because it's not in PATH and, when I display the current PATH within the script - it's not what was set in the profile.

Why doesn't the PATH set in the profile survive into the script's execution?

marked as duplicate by Jenny D, masegaloeh, Andrew Schulman, Scott Pack, Jim B Apr 28 '15 at 15:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

9

In order to set the desired environment variables you need to source the .bash_profile file with . /home/some_user/.bash_profile. In your case, you are executing the bash_profile file, which will basically execute that file and exit the shell. The next time some_script is run it will start with fresh environment variables. Check this link - sourcing vs executing

The other option is to set the PATH environment variable at the top of the crontab file. That way it will be visible to the rest of the scripts.

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