Diatribe, Macintosh, Tips, UnixAugust 19, 2008 11:41 am

I’m sure everyone with Unix experience has their own cherished best practice to compile software from source. I’ll try to tone down the soapbox.

What set me off was a TidBITS article on DNS (at work, we compiled that patch as soon as it came out). I was ready to yell at my computer screen! They got it right about the need to patch right away, but wrong on how to do it well.

The very basic process to compile from source is:
./configure
make
make install # as root

Well, I like to log the results of those three commands; if it fails to build, I’ve got something to study later without worrying about my scroll buffer. I also like the visual feedback of how the compile is going, so I also want to see the output as well as logging it to a file. The reason why make install is its own step is so that you can follow the principle of least privilege. My method does all of those things.

./configure | tee configure.out
make | tee make.out
sudo make install | tee make-install.out

Feel free to choose your own file names, or switch to root instead of using sudo (potentially more secure, but longer). However you do it, just keep in mind that logging and least privilege are Good Things.

Journal, UnixJuly 20, 2008 2:52 pm

So we all heard about the DNS flaw announced by DoxPara. Boy, was that a busy week for us! Turns out, the secure version of BIND has this little problem with CPU load, accompanied with complaints about file descriptors, above a certain number of DNS queries per second. Ouch.

The immediate key to get it under control was to add ulimit -n 4096 to named.conf so that BIND would use more of the available file descriptors. The fix with more breathing room was to install the next beta version of BIND that has better performance. We’ve been out of the woods since then, and we’re no longer expecting another shoe to flatten us.

In fact, now we can relax while those who didn’t patch have discovered that the flaw has been discovered before its scheduled public announcement … yikes!

Tips, UnixJune 24, 2008 2:26 pm

I have some scripts that echo warning messages that really should go to stderr instead of stdout. The basic form is
echo "error" >&2
but I’ve twice gotten frustrated when I’ve tried to get fancier than that (not with echo, but with other commands). The essential problem is that the redirecting to stderr needs to be the last redirection. So my quick example is
echo "error" > /dev/null >&2
where redirecting to /dev/null or a file must come before the stderr part.

Hope this saves some time!

Macintosh, Favorite Software, Project, Journal, UnixMay 22, 2008 9:58 pm

I use certain “boilerplate” text in all of my scripts for work. I use the same toolsets with the same setup in different combinations with different filtering, but getting started is always the same. So far, I’ve been happiest with Idea Knot, but I’ve always wanted to that flexibility in a format I could easily share with others.

So yesterday I started looking for a JavaScript, XML, or PHP way to display external files selectively. I did not find an easy PHP approach with Google. I found an XML merge that I thought would be easiest to configure although a little harder for others to use, but it didn’t work for me. I probably didn’t configure my input XML files properly, although they passed xmllint. I have ideas on what to tweak to get it to work, but I decided instead to maximize my time and move on to what would be easier for everyone (myself included!) to use: JavaScript. I found an excellent tutorial on including other files on a web page, with an example. There’s another example that converts the other file before displaying it. Very cool! So I whipped up a quick variant using my files, and what do you know?: it worked! Since I have no experience with JavaScript, I’m allowed to be surprised that it was easy. I even understand what the code does! Very nice.

On the first pass, I found how to do this with JavaScript with all of the boilerplate contained in JavaScript variables, but that made the monolithic web page so very large. Also, I do update my boilerplate as I learn new tricks and add new toolsets, and updating a monolithic page is tedious to say the least. So that’s when I started looking for a way move from inline variables to external files to store my code building blocks. I feel good about using good code that I understand, and storing my information in multiple external files that will be easy to maintain.

Building the code generation page and moving from Idea Know to external files will take me a while, but at least now I have all of the components needed. This will be a useful tool to share at work!

Macintosh, Tips, UnixMay 7, 2008 7:55 pm

I need to remember how to do this trick, using sed on literal tabs, which you can usually get by typing ^v. Control-V, Tab allows sed to operate on tab characters. Yes.

Tips, Journal, Unix, iPodApril 26, 2008 6:26 am

I like my iPod touch as a handheld web browser using WiFi. Yes, it’s expensive for that niche when you could probably use the slower Nintenndo DS Browser or other applications, but then you have an iPod for music, podcasts, or (my favorite) video podcasts.

However, I hit a stumbling block for a minute when I couldn’t find the tilde on the soft keyboard. Then I agreed, tilde (~) should not be used in Web addresses. Luckily I remembered %7E on my own, and I know that is URL encoding. You could use an online URL encode/decode page, a self-contained page that can be saved for offline URL encoding and decoding, sample JavaScript to write your own, or these excellent shell scripts called urlencode and urldecode.

Tips, Troubleshooting, UnixApril 15, 2008 2:58 pm

Aha! I can pass environment variables to sudo!
sudo env ARCHFLAGS='-arch ppc' python setup.py install
Or, more to the point,
sudo env LD_LIBRARY_PATH=$LD_LIBRARY_PATH sybase

Tips, UnixApril 11, 2008 6:44 am

Yesterday I needed to quit a graphical application running on my Linux laptop at work, and I couldn’t find it in a process listing. Whoops! Time for remote control! Although I had turned on VNC (”Remote Desktop” in RHEL Linux), apparently I forgot the password. So I started with how to control the gnome vino-server from the command line and moved on to how to change the vino password from the command line. I used the online base64 encoder to put the known password in with gconftool. Pretty cool!

Macintosh, Tips, UnixJanuary 10, 2008 4:01 pm

I thought I was going to go batty trying to get a reasonable blank version of Lewcid’s presentation in TiddlyWiki because I could not download a version that I could edit! Yes, I tried the #author:true URL, but nothing changed. Well, when your browser fights you, use something else!

curl -O http://lewcid.googlepages.com/presentation_empty_full.html

Anyway, now to see if I think slides in TiddlyWiki are easier than slides in S5. I’m using OmniOutliner to organize my talks, saving as OPML, and using an XSL to convert to S5. I have two problems with this approach: my notes aren’t converted from OPML to the handout (print, not slides) section, and the XSL is cruel to links and images. So before I run the XSL, I mangle the URLs with sed, XSLT, de-mangle with the reverse sed. That’s a little annoying, so I was wondering if there were something simpler. Since I use TiddlyWiki all the time …

I’ll see how it goes, but at least I crossed the first hurdle, getting a TiddlySlides file that I can edit.

UPDATE 1/11/08: the trick wasn’t actually curl; it was to quit and relaunch my browser (Firefox). Something must have been cached that prevented the #author:true from working.

,

Macintosh, Tips, UnixJanuary 3, 2008 11:54 am

I wanted to pull out just the 2008 entries from a calendar in iCal (ics) format, and import those into a calendar of my own.

At first, I went looking for an IcsToCsv converter (click on Attachments to see the Python code; there’s Ruby code for ics2csv too). My plan was to use grep to match the 2008 lines after the CSV format put the entire entry on one line. Next I realized that it was much easier to use Smultron for the CSV conversion since all the event entries were uniform.

Then I noticed I could go straight to the end game, without CSV, with judicious use of grep to include context before and after the match …
grep -B 1 -A 4 "DTSTART:2008" Exported.ics

So the Sample file I wanted to import could be created this way:
sed -n '/^BEGIN:VCALENDAR/,/^BEGIN:VEVENT/p' Exported.ics | sed '$d' > Sample.ics
grep -B 1 -A 4 "^DTSTART:2008" Exported.ics | grep -v -- "--" >> Sample.ics
tail -5 Exported.ics | sed -n '/^END:VEVENT/,/^END:VCALENDAR/p' | sed '1d' >> Sample.ics

The middle command is the good one; the first and last commands are safer to do visually because they assume that all of the iCal events are formatted just like the ones I scanned … and it can be dangerous to assume that much!

If you have problems importing, check the line endings. On my Mac, I ended up with ^M (as seen with the vis command, or with cat -etv). You can remove those with this command:
cat Sample.ics | tr -s '\r' '\n' > Clean.ics
(If you want to preserve blank lines, don’t use -s.) My import went fine. I love my command line text manipulation tools!

, , ,