Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Here's what I'd like to automate:

00 08 * * * psql -Uuser database < query.sql | mail somone@null.com -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
1  
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

2 Answers 2

up vote 28 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 somone@null.com -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 $().

Example:

export NOW=`date`
by
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
3  
but it has nothing to do with the user's question. –  Aaron Brown Nov 13 '09 at 18:53

Your Answer

 
discard

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.