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 kill and restart a specific process, the strange behaviour is that if i run the script via terminal everything works fine as expected, it shout down the process and restart it, but when the cron job is triggered it only shout down the process and nothing more…any idea why this behaviour occur? Thanks
Linux – Cron strange behaviour
bash-scriptingcroncronjobcrontablinux
Best 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
) andPATH
(=/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
orpython
you have to use/usr/bin/java
or/usr/bin/python
.