Cron strange behaviour

0

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

FabioEnne

Posted 2015-11-06T11:08:40.613

Reputation: 133

If you don't post some details (cron definition, script content...) it's hard to tell. – nKn – 2015-11-06T11:15:05.017

Answers

5

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.

jcbermu

Posted 2015-11-06T11:08:40.613

Reputation: 15 868

Or, just specify a decent value for PATH as part of your cron spec... – Chris Down – 2015-11-06T12:49:53.243