Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

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.

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

Set SHELL on your crontab:

SHELL=/bin/bash
* * * * * # your_job
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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