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?

DD.
  • 3,114
  • 11
  • 35
  • 50

2 Answers2

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.

DD.
  • 3,114
  • 11
  • 35
  • 50
3

Set SHELL on your crontab:

SHELL=/bin/bash
* * * * * # your_job
Thiago Figueiro
  • 830
  • 1
  • 6
  • 18