I’m as guilty as anyone of treating cron as if it’s “just a shell”, and it finally bit me today. I had a quick-n-dirty Postgres backup command that worked wonderfully from the command line:
/usr/local/postgres/bin/pg_dumpall -U pgadmin | gzip -9 > \
But when I put this into my crontab, I started getting error messages about an EOF being reached before finding a closing ‘`’.
The answer is not to get rid of backticks and call an external script. The answer is to simply escape the percent signs! From `man 5 crontab`:
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.