Musings of an anonymous geek

April 27, 2007

Cron != Shell

Filed under: Scripting, Sysadmin, Technology — m0j0 @ 10:55 am

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 > \
/usr/local/db/backups/pgsql/pgdump.`/bin/date +"%Y%m%d-%H%M%S"`.gz

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.

Technorati Tags: , , , , , ,

Social Bookmarks:

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

Blog at WordPress.com.