Question

i setup a crontab job to run a php script, php ~/Documents/workspace/tools/src/main/php/testcron.php > mylog

and the log file shows: JAVA_HOME is not set.

i tried export and saw JAVA_HOME="/Library/Java/Home"

i changed it to JAVA_HOME="/usr/bin" but if i open other terminal it still showed as 'Library/Java/Home' and also it complain cannot find java_home if i run php script in the same terminal that i changed the JAVA_HOME, anyone know what's wrong? thanks. im using Mac

Was it helpful?

Solution

you should specify your JAVA_HOME at the beginning of the PHP script or in your cron definition like this : * * * * * * export JAVA_HOME=/usr/bin;~/Documents/workspace/tools/src/main/php/testcron.php > mylog

You'd better set your environnement variables in a persistent manner. I'm not used to Mac, so I can't tell you the way to do it, but in Linux, you can set it in config files of shell commands like ~/.bashrc or ~/.zshrc

OTHER TIPS

in crontab add

05 * * * * /YOUR_PATH/start.sh > /dev/null 2>&1

in start.sh add above everything

export JAVA_HOME=/usr/local/java;

Where /usr/local/java is where is located java. You can use whereis java command to lacalize your java. I suggest you to use absolute path always

ATTENTION: This command starts every 5 minutes, every day!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top