I have a crontab script which runs fine from the interactive shell. However when running from crontab it fails because it doesnt run the scripts in /etc/profile.d/ (e.g. /etc/profile.d/java.sh)

Whats the best way of fixing this?


begin the shell script with:

#!/bin/bash -l

This causes bash to start as a login shell, which means it will read /etc/profile and ~/.bash_profile.

  • 1
    Not really sure if this is a good idea or not?
    – DD.
    May 30 '12 at 9:05
  • 4
    To use this idea in SLES, had to specify 11 11 * * * /bin/bash -l -exec "some && commands" right in crontab. Dec 17 '13 at 4:32

Set SHELL on your crontab:

* * * * * # your_job

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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