1

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?

peterh
  • 4,914
  • 13
  • 29
  • 44
flymike
  • 221
  • 1
  • 2
  • 6

1 Answers1

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.

Daniel t.
  • 9,061
  • 1
  • 32
  • 36