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.
Research shows that 94% of CIOs believe that enterprise mobility has become an important part of their enterprise IT strategy. While there are many benefits for business, there are still risks when it comes to security. This whitepaper looks at the steps all organisations to take when it comes to supporting a mobile workforce.
- FTSenior Consultant | Project work | National Systems IntegratorVIC
- FTField EngineerNSW
- FTMid level IT consultant | Systems Integration & Managed ServicesNSW
- FTLinux Administrator with AWS & DevopsNSW
- FTManual Test Engineer | Financial Institution | Web testingNSW
- FTSystems Administrator - Managed ServicesNSW
- FT1st & 2nd level IT support all-rounder in beautiful rural BathurstNSW
- FTLevel 2 IT Support TechnicianVIC
- CCE-Commerce - Senior Web Application DeveloperNSW
- FTSystems Administrator | National commercial law firm | MS, AWS & eDiscoveryNSW
- CCMilitary simulation programmer with C# and Unity - 3 monthsNSW
- FTAndroid DeveloperNSW
According to IDC, sixty percent (60%) of business critical information is now stored, sometimes exclusively, in email. It۪s more important than ever to establish an email archiving strategy that ensures business continuity and information availability. Modern email archiving solutions are changing to accommodate the new realities of the digital workplace and can intelligently store, manage and discover email content to meet business and compliance requirements. Read this paper to learn how to solve your top email challenges.
- Amazon wants companies to get onto its cloud using new services
- AWS assures customers they're atop the cloud
- Microsoft: Go old-school to lock down Office from changes
- Google, WhatsApp integration lets users back up messages on Android
- Arista stock up on review of Cisco patent claims
- New service helps pull data into AWS from the Internet of Things
- Zendesk tool taps machine learning to nip customer-service problems in the bud
- Amazon launches QuickSight business intelligence service
- Microsoft expands FastTrack service to aid Office 365 migration for businesses
- Microsoft claims 110M devices now run Windows 10
- Greens call for Trans-Pacific Partnership assessment
- Verizon will use its mobile supercookie to target customers with AOL ads
- 8 tech startups ink $400K in new contracts
- EU Safe Harbor ruling could have bearing on Microsoft email dispute
- IPsoft's 'Amelia' virtual assistant just got a whole lot more human