4

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?

0

2 Answers 2

6

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.

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

Set SHELL on your crontab:

SHELL=/bin/bash
* * * * * # your_job

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .