Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here's what I'd like to automate:

00 08 * * * psql -Uuser database < query.sql | mail -s "query for `date +%Y-%m-%dZ%I:%M`"

Here's the error message:

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
share|improve this question
Apart from the giving error consider to put this in a schell script. It will pretend the crontab to be clumsy and you can add comments and config to your script file. – PeterMmm Nov 13 '09 at 15:09
up vote 40 down vote accepted

From crontab(5):

The ``sixth'' field (the rest of the line) specifies the command to be run. 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. 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. There is no way to split a single command line onto multiple lines, like the shell's trailing "\".

Just add backslashes before % signs:

00 08 * * * psql -Uuser database < query.sql | mail -s "query for `date +\%Y-\%m-\%dZ\%I:\%M`"
share|improve this answer
Excellent. Thanks. – Terry Lorber Nov 13 '09 at 15:48

I had a lot of problems with backticks also. Sometimes you need more than one occurrence of quotes and backticks. Just replace them for $().


export NOW=`date`
export NOW=$(date)

-Gilson Soares

share|improve this answer
+1 This is the favoured syntax nowadays anyway. – Dan Carley Nov 13 '09 at 17:05
but it has nothing to do with the user's question. – Aaron Brown Nov 13 '09 at 18:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.