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.
This whitepaper is the second in a three-part series on distributed denial of service attacks (DDoS) and multi-tier DDoS protection. This section details the design and capabilities of different forms of protection architecture designed for a variety of circumstances, while also providing alternative approaches. The paper also explains how to maintain availability, including network and application defense and DNS DDoS Mitigation.
- FTMicrosoft Business Intelligence ConsultantNSW
- FTCampaign Managers | RTB | Display + Video | Trading desk |SydneyNSW
- FTExecutive Producer/Head of Production: Advertising AgencyNSW
- FTOBIEE BI/DW ConsultantNSW
- FTBrand Relationship Manager | RTB Trading Desk | Digital Advertising | SydneyNSW
- FTMicrosoft Business Intelligence DeveloperNSW
- FTIT Support EngineerNSW
- FTDeliverability SpecialistNSW
Distributed denial of service attacks (DDoS) attempt to make a machine or network resource unavailable to its intended users, with a wave of crippling attacks on enterprises since 2012. This whitepaper offers guidance to security and network architects in designing, deploying, and managing architecture to protect against increasingly sophisticated, application-layer DDoS attacks.
- Teardown: Galaxy S5 parts cost 21% more than iPhone 5S
- Oracle identifies products affected by Heartbleed, but work remains on fixes
- Developers get access to more Sony camera features
- Microsoft slashes Windows XP custom support prices just days before axing public patches
- Tata revenue, profit up on strong outsourcing demand
- German researchers hack Galaxy S5 fingerprint login
- Telefónica starts exchange for targeted mobile ads
- Glass all gone after one-day sale, Google says
- Mt. Gox has filed for liquidation in Japan, says report
- Microsoft's Chinese partner confident Xbox can compete against Android consoles
- Australia needs effective government cyber policy leadership: report
- Court slaps TPG with $400k fine over 000 failure
- Lycamobile issued warning for over-charging customers
- TPG should pay rural levy for each FTTB service: NBN Co
- Ukraine tensions could hurt international security efforts, Kaspersky says