2011-07-28

Banned by Google+

That didn't take as long as I thought it might. A rundown of what happens: Your google profile goes wonky as shown in the photo. GMail, Docs, Picasa, Voice and Talk all work fine, although anywhere you would expect to see your profile photo, it will be missing. You can view other people's content in Buzz, Reader ans Plus, but you cannot share, post, comment or otherwise produce any content on those services, nor, apparently, can you follow new contacts either.

Most people that I collaborate with elsewhere know me as ax0n. My real name, address, phone number etc are no secret, but most people don't even know who I am by my given name.

By for now, Google+.

2011-07-24

Lock Fail

Simplex-style pushbutton locks are ubiquitous in the medical industry. They're used on medicine carts, cabinets, lockers and doors. This is a cabinet that is designed to hold a thin-client workstation and/or patient record portfolios, and restrict access to ethernet ports.







Yep. You can open this one by sliding the exposed latch with your finger.


Also: if you happen to shoulder-surf the code for one of these, you can almost guarantee every other cabinet in the same hospital uses the same code.

2011-07-17

Sysadmin Sunday: parse strings with spaces using shell script

I run into this once in a while: I'm trying to perform some operation on a bunch of files or a big line of text, and a space in the filename or text file janks everything up. Take for example all these recordings from a podcast that got batch-named with spaces in them.


Chimera:Recordings axon$ ls
(110) - .mp3 (12) - .mp3 (18) - .mp3 (39) - .mp3 (79) - .mp3
(111) - .mp3 (15) - .mp3 (3) - .mp3 (70) - .mp3

I really don't want spaces in the names. No problem, just use ls -1 (the number one) to list the files on their own line, and use sed or something for renaming them and changing every space to a null character, right?

Chimera:Recordings axon$ for file in `ls -1`
> do mv "$file" `echo $file | sed s/" "//g`
> done
mv: rename (110) to (110): No such file or directory
mv: rename - to -: No such file or directory
mv: rename .mp3 to .mp3: No such file or directory
mv: rename (111) to (111): No such file or directory
mv: rename - to -: No such file or directory
mv: rename .mp3 to .mp3: No such file or directory
[truncated]

That did not go as planned...

There are a few interesting ways to solve this one. The actual reason for this problem is your shell's internal field separator. When iterating over some input (here, the results of "ls -1"), the shell interprets any kind of whitespace as a field separator, including spaces, tabs and newline characters.

Although there are some other clever ways to get around this limitation when dealing with filenames specifically, my favorite solution to this problem works on any whole line of input regardless its source, whether reading a text file and operating on it one line at a time or taking filenames as input from another command such as ls or find. You simply have to use something that can accept spaces and requires a newline character in order to set a variable. Of course, I'm talking about a rather unsavory (but totally viable) use of the read command, which most unixy shell-script writers are familiar with when they require user input. Check it:

Chimera:Recordings axon$ ls -1 | while read file
> do mv "$file" `echo $file | sed s/" "//g`
> done

Chimera:Recordings axon$ ls -1
(110)-.mp3
(111)-.mp3
(12)-.mp3
(15)-.mp3
(18)-.mp3
(3)-.mp3
(39)-.mp3
(70)-.mp3
(79)-.mp3

You can also remap the $IFS variable to contain a newline, but be sure to unset it afterwards (if using BASH, this will set it back to default), or your shell will act differently than you likely expect when you're done. Messing with the internal field separator can be useful for other things (such as parsing /etc/passwd or handling CSV files) but honestly I'd probably be more inclined to use awk for those. If we remap IFS to a newline, our original script that errored out above works just fine.

Chimera:Recordings axon$ IFS=`echo -en "\n\b"`
Chimera:Recordings axon$ for file in `ls -1`
> do mv "$file" `echo $file | sed s/" "//g`
> done
Chimera:Recordings axon$ ls -1
(110)-.mp3
(111)-.mp3
(12)-.mp3
(15)-.mp3
(18)-.mp3
(3)-.mp3
(39)-.mp3
(70)-.mp3
(79)-.mp3
Chimera:Recordings axon$ unset IFS