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.
Flash storage represents a quantum leap from the storage layer in terms of performance, however it is crucial companies understand their I/O profile in order to formulate a successful storage strategy. Find out in this eBook how flash storage can be beneficial for enterprises and useful questions to ask before making an informed decision on the purchase.
- FTNetwork EngineerNSW
- CCSenior Systems Engineer - SCOM/SCCM/PowerShellVIC
- CCMultiple Java rolesACT
- CCAEM DeveloperNSW
- CCSAP ABAP ProgrammersACT
- FTSenior Linux Sys AdminNSW
- FTIT Support AnalystNSW
- CCSolution Architect - Biomedical - South Australia locationSA
- FTSenior Mobile Developer - IOSNSW
- CCContract System Engineer (Lotus Domin) 160129/SE/vccAsia
- CCApplication Support AnalystNSW
- CCHelpdesk SupportNSW
- CCJava DeveloperVIC
- FTJunior Developer | C#, MVC & SQL | Class FinanceNSW
- FTSenior Unified Communications Consultant - National IT ServicesNSW
- FTSenior Project Manager - SecurityNSW
- FTSenior Front End Developer Required Working World Leading Digital TeamVIC
- CCTechnical Integration Specialist - MicrosoftACT
- CCiOS Developer - New AppNSW
- CCContract Analyst Programmer(Crystal Report/Oracle)160127/AP/vhsAsia
- CCContract Analyst Programmer (MS.Net/Visual Basic) 160129/AP/vtdAsia
- FTJava or Ruby Web DeveloperVIC
- CCContract System Analyst (MSSQL/.Net/Mobile App) 160122/SA/vhaAsia
- FTSolution ArchitectNSW
- CCApplications DeveloperQLD
Internal and external disruptions can impede business continuity and result in negative repercussions for enterprise productivity and data resources. This whitepaper looks at how improved mobility access can shield companies from unprecedented risks, resulting in greater cost savings and enhanced workforce continuity. It also highlights the benefits of having a mobile workspace technology which enables the workforce to have access to apps, desktops and files in difficult situations. Included are four case studies where organisations are able to demonstrate a high level of business continuity with sound disaster recovery strategies in place.
- Modular cellphone kit can be used for IoT and wearables
- Dragula looks to take the bite out of drag-and-drop
- Mozilla sets kill date for Firefox OS on phones
- LTE-U’s cold war may be thawing, as field testing commences ahead of summit
- Now that AI has mastered 'Go,' are all our jobs next?
- Make a $40 Linux or Android PC with new Raspberry Pi 2 rival
- Researcher finds serious flaw in Chromium-based Avast SafeZone browser
- Fed up with bogus computer support calls, man turns tables on scammers
- Dridex banking malware mysteriously hijacked to distribute antivirus program
- SamsaraJS: Famo.us fork juices mobile Web UIs
- UN panel backs WikiLeaks' Julian Assange, but he may not go free
- The Neutrino exploit kit has a new way to detect security researchers
- 7 smartphone trends to watch this year
- What businesses need to know about Privacy Shield
- Box makes it easier for businesses to control encryption of cloud data