Yikes! Something strange in a cron job.

Joshua Marsh joshua at themarshians.com
Sat Feb 8 15:14:17 MST 2014

On Sat, Feb 8, 2014 at 2:59 PM, S. Dale Morrey <sdalemorrey at gmail.com>wrote:

> This makes me wonder if I need to specify HOME as in "export HOME=/root"
> I'm going to give that a shot and see if it solves the problem.
It may depend on what version of cron you have installed. Here is what mine
says about it:

       Several  environment  variables are set up automatically by the
cron(8) daemon.  SHELL is set
       to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd line
of  the  crontab's  owner.
       PATH  is  set to "/usr/bin:/bin".  HOME, SHELL, and PATH may be
overridden by settings in the
       crontab; LOGNAME is the user that the job is running from, and may
not be changed.

When I had a problem like this before, the thing that fixed it for me was
to wrap the command in a script. So, your cron entry might be:

0 1 * * * /bin/bash /root/backup_mysql.sh

and then your script would simply be:

mysqldump dbname

I never figured out the actual problem, but I'm sure it was related to
environmental variables like you suggest or perhaps the difference between
/bin/sh and /bin/bash.

More information about the PLUG mailing list