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:
About these ads

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 69 other followers

%d bloggers like this: