Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 2 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
1  
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
add comment

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.