2

Here's the issue I'm having...

I have a webserver that sees a fair bit of traffic. I want to keep a near real time backup of it on another server. That backup server will process log files, visitor tracking files, DB backups, etc. So I have several commands being executed at different times via cron on the backup server (crontab -e). For whatever reason I was only getting mail for some of the executions so I added logging today.

I don't think any of the commands under the user's cron are executing. (And they didn't under the root cron either - sudo crontab -e.) Below is an example of a command that runs fine from the CLI but not from the cron. The directory /media/eagle805 is a directory on the backup server where the primary server (eagle805) is mounted. The directory is owned by the user who owns the cron.

*/1 * * * * mv /media/eagle805/ver1/php/VisitorTracking/data/raw/*.raw /var/www/ver1/php/VisitorTracking/data/raw/. >> /var/www/backups/visitor_tracking_file_move_$(date +%Y-%m-%d).log 2>&1

When I run this command from the CLI it works fine. The log file is created (and empty). All the files I want moved from the primary to the backup server are moved. But it doesn't run from cron. I am getting this error (via email):

/bin/sh: 1: Syntax error: end of file unexpected (expecting ")")

Can anyone tell me what I'm missing?

Thanks

1 Answer 1

3

You should escape the percent signs with a backslash:

*/1 * * * * mv /media/eagle805/ver1/php/VisitorTracking/data/raw/*.raw /var/www/ver1/php/VisitorTracking/data/raw/. >> /var/www/backups/visitor_tracking_file_move_$(date +\%Y-\%m-\%d).log 2>&1

Reference: man 5 crontab reads near the middle:

Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

1
  • That appears to have done the trick. Thanks, I imagine that saved days of beating my head against a wall. Aug 28, 2013 at 19:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .