On reading documentation when programs don't work as expected
No matter how often you use UNIX tools, once in a while you get caught out trying to put everything together. This happened this morning while I was setting up a cronjob and it didn't work as expected.
This happened to me earlier this week when I tried to setup a quick cron script to dump the contents of an SQL table every day. I had set it up as follows:
37 3 * * * /usr/lib/postgresql/8.2/bin/pg_dump db -U backup -t table | bzip2 - > /backups/table-monitoring/`date +%Y%m%d`.table.sql.bz2
I checked the next day that things were working and found the directory empty. Interesting.
After a quick check of my email I found the culprit:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"' /bin/sh: -c: line 1: syntax error: unexpected end of file
This is where things got complicated. Had I checked crontab(5) this story would probably have ended here. I didn't.
After a couple of attempts at escaping this command line to make things work I ended up with the following:
backup:~% ls /backups/table-monitoring | head -n 3 `date \+%Y%m%d`.table.sql.bz2 date +%Y%m%d.table.sql.bz2
Even more interesting...
Turns out the answer is quite simple. The man page has this to say about it:
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 "\".
Ooops. A quick change later, I end up with the following snippet:
37 3 * * * /usr/lib/postgresql/8.2/bin/pg_dump db -U backup -t table | bzip2 - > /backups/table-monitoring/`date +\%Y\%m\%d`.table.sql.bz2
I'm still wondering about the usefulness of the % to send data to the standard input as opposed to using standard pipes though.
If you’re looking for your first ERP system or looking to upgrade from an existing system, the evaluation, selection and implementation process is a long-term strategic decision for your organization. To help you through this process, here are eight simple steps for a successful ERP system selection.
A decade or so ago, security wasn’t nearly as challenging as it is today. Users, data and applications were all centralized in data centers that, in effect, kept them contained within a network perimeter. This eBook outlines how the open enterprise has changed the role of security.
- Queensland Ambulance Service invites offers for iOS report form
- ABS develops Web service for users to create own population clock
- Rogue employees using photocopiers and email services to steal data
- Connected home brings new revenue opportunity for telcos: Ovum
- Melbourne recruitment firm fined $11k for Office 2007 piracy
- Blow up your website and start over
- Until the Tails privacy tool is patched, here's how to stay safe
- Telstra unveils interoperable videoconferencing service
- Apple will 'set the world on fire' with iPhone 6 sales
- LTE network for US public safety taking it one step at a time
- A new tool for disasters: The personal antenna
- Phone unlocking bill clears US House, next step is president's signature
- Apple hasn't exhausted its supply of Yosemite betas
- Oracle's new in-memory database option could spark unanticipated costs, expert warns
- Bose sues Beats over headphone patents