I've been going through all the various questions about why a specific script run in cron and nothing has helped me thus far. So I'm just trying to run a mysqldump script that now looks like this:
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# you must pass arguments to this script
if [ $# -eq 0 ]
then
echo "No arguments supplied"
exit 1
fi
# if a path is supplied, perform the mysqldump to that directory
today=`date +%m-%d-%Y`
mysqldump --defaults-file=/home/<user>/.my.cnf --databases 360_projects --single-transaction --add-drop-database --triggers --routines -u BACKUPUSER > $1pmbackup${today}.sql
Notice that I've added explicit paths, let it know that I want to run it in bash, and in mysqldump that I'm manually specifying the path to my config file in case cron doesn't pick it up. None of this has helped thus far.
And finally my crontab, which I invoke using crontab -e
so that it automatically installs when I quit my editor.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# Backup of MySQL Database every 4th Hour, Locally, Remotely
6 11 * * * /bin/bash /home/<user>/Scripts/sql-backup.sh /media/mysqlBackup-Daily/
I've made sure of course that my script is owned by the user to which this crontab belongs and the permissions are set to rwxr so I'm really not sure where this is going wrong.
Output of my /var/log/cron for that specific time when I was trying to test it:
Aug 21 14:06:01 www5 crond[1305]: (<user>) RELOAD (/var/spool/cron/<user>)
EDIT: Perhaps the best question for the time being is simply how to get more verbose output from a cron job. Right now, all I'm getting is a line telling me it reloaded (see above).
EDIT 8-27-18: I noticed the suggestion to use logger to get more verbose output but that doesn't seem to be working. My error now changed to:
Aug 27 13:55:01 www5 crond[1305]: (php) ERROR (getpwnam() failed)
From the command:
*/5 10 * * * /bin/bash /home/<user>/Scripts/sql-backup.sh /media/vantecBackup1/mysqlBackup-Daily/ 2>&1 | /usr/bin/logger -t sql_daily_backup
What do you make of this error? It doesn't make much sense to me since the script does not use php. Thanks.
--defaults-extra-file
instead of--defaults-file
. Also you should specify full path for anything you are running, e.g.,/usr/bin/mysqldump
sudo crontab -e
so it has root privileges?Aug 21 19:28:01 www5 crond[1305]: (root) RELOAD (/var/spool/cron/root) Aug 21 19:28:02 www5 CROND[20320]: (pcp) CMD ( /usr/libexec/pcp/bin/pmie_check -C)