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.
In this White Paper, IDC offers up some quantifiable benefits that Asian enterprises have observed as a result of deploying backup and recovery solutions. · Many enterprises are finding that the backup and recovery processes and technologies that they have implemented have not kept pace with the demands of the business · IDC identifies how organizations can experience savings and improvements from the deployment of different types of technologies · The benefits fall into three categories: storage environment cost savings; end-user productivity enhancements; and IT staff productivity optimization
- CCTech Support | IT Services Firm - Ad hoc Projects - Echuca AreaVIC
- CCTech Support | IT Services Firm - Ad hoc Projects - Port Augusta / Whyalla AreaSA
- FTSearch/SEO/SEM/PPC - Multiple OpportunitiesVIC
- FTStudio Design ManagerVIC
- FTSearch/SEO/SEM/PPC - Multiple OpportunitiesNSW
- FTAcquisition Marketing ExceutiveNSW
- FTProgram Manager - Integration & SolutionsNSW
The BYOD trend is increasing, and for good reason. Great benefits are in reach, but they will never be realised unless there is a well-written policy and a robust management platform. This guide will show you how to create a strong policy so you can reap the BYOD rewards. •Learn why you must address your BYOD policy if you want to create a peaceful, secure, and productive mobile environment •See which areas and questions you should be focusing on to build your policy •Calculate the ROI of implementing a BYOD policy rather than/in association with a corporate-owned model
- Apple's Black Friday sale includes iPhone for the first time
- France, Germany want EU to take a tougher stance on tech firms
- Coming soon: Murder by Internet
- Distracted? Slap this Hitachi gizmo on your forehead to focus
- Uber suspends Nevada operations, affecting nearly 1,000 jobs
- Sony confirms development of e-paper smartwatch
- Sydney Startup Weekend doubles attendance in one year
- ASIC unhappy with exclusion from data retention regime
- Australian Internet Security Initiative portal launched to help ISPs
- How SBS scaled up for FIFA World Cup online
- Hail pounds telecom networks in Queensland
- RMIT University builds virtual networking labs for students
- Weather.com fixes web application vulnerabilities
- Early version of new POS malware family spotted
- Syrian Electronic Army posts hacking message on several news sites