Hopefully I am posting it in the right forums..
Basically, I am trying to run a script that will do a MySQL database dump which works when I run it manually, but crontab doesn't seem to run that particular script for some reason.
My crontab is setup as such (for testing purposes, running every minute):
* * * * * /opt/lampp/htdocs/xyz/backup/backup.sh
The script is setup as such:
#!/bin/bash
# Script to backup the database
/opt/lampp/bin/mysqldump -u root xyz > backup_$(date +%Y%m%d).sql
echo " backup_$(date +%Y%m%d)" > /opt/lampp/htdocs/xyz/backup/log.txt
I know the script runs, because the log.txt is created. But for some reason, no SQL file is generated. I also know that the line
/opt/lampp/bin/mysqldump -u root xyz > backup_$(date +%Y%m%d).sql
works because it generates the file if I run it at the command line.
Any help greatly appreciated!
解决方案
So when crontab runs the shell script, the backup_(date).sql file is actually saved under the /root folder.
Running the shell script manually places the SQL file where the shell script is.