I've got a Bash script with all the permission to be excecuted, I attach it to to a cron job, this script basically only kills and restarts a specific process. The strange behaviour is that if I run the script via terminal everything works fine as expected, it shuts down the process and restarts it. But when the cron job is triggered it only shuts down the process and nothing more...any idea why this behaviour occur?
1 Answer
Keep in mind that a script running in cron does not have the same environment as a script running in shell.
The cron daemon starts a subshell from your HOME directory.
The cron daemon supplies a default environment for every shell, defining HOME
, LOGNAME
, SHELL
(=/usr/bin/sh
) and PATH
(=/usr/bin
).
Do not depend on environment variables. This includes path setting, x11 settings, or anything else.
Use full path, for example:
instead of simply calling java
or python
you have to use /usr/bin/java
or /usr/bin/python
.
-
Or, just specify a decent value for
PATH
as part of your cron spec... Commented Nov 6, 2015 at 12:49