Skip to content
Advertisement

Cronjob script isn’t working as expected

I have a script that work perfectly fine when I manually run it by myself, but does not seem to run properly from crontab.

The main error is that the (external) environment variables are not being set.

I added SHELL=/bin/bash above the cronjob definition but still got the same errors.

The script I have copied and pasted below. Cheers for the help

JavaScript

The error as you can see below all the environment variables return:

JavaScript

Advertisement

Answer

As @that-other-guy pointed out, the environment variables $MYSQL_ENV_MYSQL_DATABASE, $MYSQL_ENV_MYSQL_ROOT_PASSWORD are not set.

Environment variables are inherited from process to children when a process forks. This means that the crontab jobs, will inherit the environment from the crontab service. Environment variables set in the shell when you install the crontab job, will not be preserved.

You should add in your shell script:

JavaScript
Advertisement