2

I have a command in my crontab that doesn't execute correctly, this should backup the database everyday at the specified time. I tried running the command in my terminal and is working properly.

To edit my crontab I use crontab -e the current cron tab contains the following:

# Save online agent status every 2 minutes
*/2 * * * * /usr/bin/python /home/dummy/scm/qt-savu/userstatus.py >> /home/dummy/qt-savu/userstatus.log

# Save Hourly call counts every XX:59
59 * * * * /usr/bin/python /home/dummy/scm/qt-savu/hourlylog.py >> /home/dummy/qt-savu/hourlycc.log

# Backup albatross everyday
58 5 * * * /usr/bin/mysqldump -udummy -ppassword albatross | /bin/gzip > /home/dummy/Documents/backups/`/bin/date +%y.%m%d`.albatross.tar.gz

# Backup bert everyday
58 5 * * * /usr/bin/mysqldump -udummy -ppassword bert | /bin/gzip > /home/dummy/Documents/backups/`/bin/date +%y.%m%d`.bert.tar.gz

Other commands in the crontab are working properly, The commands that are not working are:

# Backup albatross everyday
58 5 * * * /usr/bin/mysqldump -udummy -ppassword albatross | /bin/gzip > /home/dummy/Documents/backups/`/bin/date +%y.%m%d`.albatross.tar.gz

# Backup bert everyday
58 5 * * * /usr/bin/mysqldump -udummy -ppassword bert | /bin/gzip > /home/dummy/Documents/backups/`/bin/date +%y.%m%d`.bert.tar.gz

The log output looks like this

Sep  4 05:56:01 luna CRON[18815]: (dummy) CMD (/usr/bin/mysqldump -udummy -ppassword bert | /bin/gzip > /home/dummy/Documents/backups/`/bin/date '+)
Sep  4 05:56:01 luna CRON[18812]: (CRON) info (No MTA installed, discarding output)
Sep  4 05:56:01 luna CRON[18817]: (dummy) CMD (/usr/bin/mysqldump -udummy -ppassword albatross | /bin/gzip > /home/dummy/Documents/backups/`/bin/date '+)
Sep  4 05:56:01 luna CRON[18813]: (CRON) info (No MTA installed, discarding output)

As I observed the output of the log stops at /bin/date.

Giacomo1968
  • 58,727

1 Answers1

4

% is treated specially by cron. It is used to denote the end of the command portion and the beginning of standard input. As such, you must escape it, like so: \%.

From the crontab man page:

The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file.

alienth
  • 321