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.
UXC Connect’s Jesmond Psaila says that DevOps can do for IT operations what Agile did for software development. This paper demonstrates how, by combining both approaches, you can significantly improve operational efficiency and time-to-market. • Marketing and development teams want to constantly change or increase functionality, while IT operations teams want to keep the environment as stable as possible • Agile software development and virtualisation have not solved the time-to-value problem faced by marketing and IT operations teams • Recent movements in DevOps aim to address and redefine a more agile service management platform, while new tools have vastly improved functionality to configure and automate common processes
- FTSenior Media TraderNSW
- FTDigital Media PlannerNSW
- FTDigital Account Manager X 3 | Display + Video advertisingNSW
- FTCampaign Managers | RTB | Display + Video | Trading desk |SydneyNSW
- CCL2 Technical Support Engineer - RightFax/MessagingVIC
- FTMachine Learning | JAVA | San Fran based global Company | SydneyNSW
- FTCampaign Managers| RTB / Programmatic | Expression of InterestNSW
- FTChief Information OfficerNSW
Mobile devices present a unique dilemma to the enterprise. On the one hand, workers empowered with tablets and smartphones can transform the way they do business; they’re more agile, closer to customers and more productive. Bring Your Own Device (BYOD) programs give users the freedom to work on the devices of their own choosing, while still allowing an enterprise to reap the productivity benefits of these always connected, readily accessible mobile devices.
- Backoff malware infections are more widespread than thought
- IBM Watson cooks up some new dishes
- Apple will keep pushing for a sales ban on Samsung products
- Facebook testing mobile searches for old posts
- Appeals court denies Oracle request to restore $1.3 billion judgment against SAP
- Scientists create one robot brain to rule them all
- Intel amps up desktop performance with its first 8-core PC chip
- IDC: Tablets sales growth to slow this year
- Can SDN usher in better IT security?
- Chrome for Mac to desert early Intel Mac owners by October
- Mozilla presses forward with new revenue plan, debuts ads in Firefox preview
- Drivers want their cars to get to know them better
- Nokia's navigation service Here comes to Samsung smartwatch and Galaxy
- As smartphone screen sizes max out, stylish designs expected at IFA
- CryptoWall held over half-a-million computers hostage, encrypted 5 billion files