CRON Job Keeps Failing

mysqldump -u root -ppassword theipb | gzip -c > /home/domain/public_html/_db_backups/$(date "+%Y%M%d%H%m").theipb.sql.gz

The above command runs fine from ssh, but when added as a cron job on simple control panel it never completes.  Is there a syntax error in it for the control panel?
LVL 12
Nathan RileyFounderAsked:
Who is Participating?
 
woolmilkporcCommented:
Hi,

a particularity of cron is that you must escape the percent signs (%) with a backslash (\%).

Next, you should always specify the full path of any executable.

Finally, please be aware that cron doesn't start a true login shell, so the user's shell initialization profiles will not be executed!

wmp


0
 
mjagdisCommented:
Unescaped '%'s are converted to newlines and everything after the first is sent to the command as standard input. See the man page for crontab(5).
0
 
omarfaridCommented:
For crontab jobs to run successfully, and in your case, please do the following:

create a shell script file
set required env variables in it (or you may source a .profile file using . /path/to/.profile)
add the above command to it (use full pathnames for command, etc)
make the script executable
add it as a crontab job by referring to its full pathname

you may read the crontab log file to check for error messages , or you mar redirect standard error to a file ( 2> /path/to/mylogfile)
0
 
omarfaridCommented:
you may use >> & 2>> for redirection of output and standard error rather than > & 2> to accumulate output and error messages
0
 
droydenCommented:
Make sure you define your PATH var in your crontab to ensure the.binaries are found
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.