# Issues with Cron & AutoMySQLBackup



## Mayhem30 (Nov 9, 2016)

I've had my AutoMySQLBackup script running on crontab without issues for years now. About a week ago, I accidentally emptied out my entire home folder (where the script / backups are stored). I downloaded the latest version of AutoMySQLBackup and put all the login / storage folder information back in the file.

For some reason, the file will no longer run via crontab - but runs perfectly fine when I run it manually.

Crontab:

```
2 0 * * *    /usr/home/backup/automysqlbackup.sh
```
Error:

```
###### WARNING ######
Errors reported during AutoMySQLBackup execution.. Backup failed
Error log below..
/usr/home/backup/automysqlbackup.sh: line 508: --user=backup: command not found
```
Line 508 :

```
${MYSQLDUMP} --user=${USERNAME} --password=${PASSWORD} --host=${DBHOST} ${OPT} ${1} > ${2}
```

Like I mentioned, if I run it manually it works perfectly. When crontab fires, I get nothing but errors. Any ideas?


----------



## tingo (Nov 9, 2016)

It looks like the variable ${MYSQLDUMP} in your script evaluates to "". How do you set it? (How is it assigned?)
FWIW, one of the most common "aha" moments for people related to cron and crontab is when they realize that the environment cron runs the scripts in is different (very different) from what root and regular users have.
Do not rely on environment when writing scripts for cron. Declare anything the scripts need explicitly, and use absolute paths.


----------



## Mayhem30 (Nov 9, 2016)

I didn't create the script, but it uses absolute paths to define all the variables.

This script has worked for 5+ years in cron, it just doesn't make any sense why "all of a sudden" it will no longer work.


----------



## tingo (Nov 11, 2016)

Well, I guess it is time for you to read and understand the script then. How else are you going to figure out what made it break?
Some assumption written into the script  is no longer true; it could be because something changed, or because whoever wrote the script made a bad assumption.


----------



## SirDice (Nov 11, 2016)

My first guess would be something like this that's causing problems:

```
MYSQLDUMP=`which mysqldump`
```
This would evaluate to an empty string if the MySQL client wasn't installed.


----------



## SirDice (Nov 11, 2016)

Oh, after actually looking at the files, the error isn't related to the scripts linked here: https://sourceforge.net/projects/automysqlbackup/

So, you probably have an old version of that script. The scripts I just downloaded don't mention ${MYSQLDUMP} at all and simply assumes mysqldump can be found through PATH.


----------



## gkontos (Nov 11, 2016)

I am using this on many servers for years. Make sure that you have the BASH path declared correctly.

```
1 2 * * * root /usr/local/bin/automysqlbackup -f /usr/local/etc/myserver.conf >/dev/null 2>&1
```
Also, make sure that you provide the correct config file.


----------



## Mayhem30 (Nov 12, 2016)

It appears when I re-downloaded the script, I got a later version that I was originally using. I had to revert back to v2.5 (released in 2006) in order for everything to work again.


----------

