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 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
  • 1
    If you don't post some details (cron definition, script content...) it's hard to tell.
    – nKn
    Commented Nov 6, 2015 at 11:15

1 Answer 1

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.

1
  • Or, just specify a decent value for PATH as part of your cron spec...
    – Chris Down
    Commented Nov 6, 2015 at 12:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .