0

I am trying to run the following in cron to back up a server every morning at 4am:

0 4 * * * dump -0uan -f - / | gzip -2 | ssh -c blowfish user@server dd of=/backups/`hostname`_`date '+%m-%d-%Y_%k%M%S'`.dump.gz

Running the command on it's own from the shell works fine. Usually when this happens the problem is due to paths, so I tried adding full paths in cron:

0 4 * * * /sbin/dump -0uan -f - / | /usr/bin/gzip -2 | /usr/bin/ssh -c blowfish user@server /bin/dd of=/backups/`hostname`_`date '+%m-%d-%Y_%k%M%S'`.dump.gz

and still no luck. I checked the system log and saw this:

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file

The same error occurs with and without paths specified. Should be a pretty simple command. Is cron executing this differently than it is written?

user2395126
  • 297
  • 1
  • 4
  • 10
  • 2
    You should escape percent sign. I've found answer [here][1]. [1]: http://serverfault.com/questions/274475/escaping-double-quotes-and-percent-signs-in-cron – Vladimir May 28 '15 at 16:48
  • Doh! That was it. Guess I never had to use % signs in a command directly in cron before. Make it an answer and I will accept it. Thank you. – user2395126 May 28 '15 at 17:03

1 Answers1

1

Escape the percent sign, or put that whole line in a script and trigger that instead.

kasperd
  • 29,894
  • 16
  • 72
  • 122
Petter H
  • 3,383
  • 1
  • 14
  • 18