Add ESR’s “The Art of Unix Programming” to my list of books I need to read. It sounds highly intriguing.(0)
Archive for the 'UNIX' Category
I was working with a bunch of Excel data this weekend for my CS project, and at some point I decided I wanted to transpose a table of data. You know, swap the rows and the columns? Simple, right?
Well, I tried searching Excel help, and had no luck. A quick google search didn’t immediately yield the answer. And I asked my CS partners, but they also had no clue. A few of them even asked other people they knew in the lab, and still no luck.
For a bunch of CS majors, I was amazed by how little they all knew about Excel. Hell, that I was the one manning Excel in my group (because I knew the most about it) kinda says a lot by itself. I mean, I can get around in Excel, but I wouldn’t dare list Excel on my resume. I know how complicated that sucker is, and I know that I can barely scratch the surface.
So I shrugged and decided I was going to write a perl script to transpose colon-delimited data that I could export from Excel. Perl is, afterall, my swiss-army chainsaw. What’s the point of having a chainsaw if you’re not going to use it? And besides, I figured it wouldn’t take me more than 5 minutes to write, and I’d already spent at least that long trying to figure out how to do it with Excel.
But before I started, I had to go to the bathroom. And when I got back, one of my partners had found the “Paste Special” option, which, among a bunch of other handy features, includes a “Transpose” option. So much for showing off my perl-fu.
So at work, I’ve been doing a lot of work with Mac OS X’s NetInfo database. In particular, I’m generating password and group files to import into the database via the niload command. Since I wanted “old” accounts to be deleted from my OS X clients, I looked at
man niload, and found the following option:
- -d: Delete entries which are in the directory, but not in the input.
Exactly what I wanted, right?
Heh, after I spent an hour tonight beating my head against `
niload -d` not deleting entries that weren’t in the input, I absent mindedly typed `
niload --help,` and here’s what I saw (emphasis mine):
- -d: delete (override) existing entries from NetInfo when the input contains a duplicate name
-m: merge new values into NetInfo when the input contains a duplicate name
Note: only one of -d or -m may be used. If neither is given, existing entries in NetInfo will be unchanged if there are duplicate names in the input
Gah! Inconsistent documentation is the bestest! So this means that I’ve got to iterate through each entry currently in the NetInfo database, and if that entry isn’t in the in the input (and isn’t some form of “local” account), then use `
niutil destroy ...,` which makes me sad.
YAFHW = Yet Another Hour Wasted.
Today while mucking around in NetInfo on the OS X machine at work, my jaw fell open when I noticed a more problematic local security problem than this nonsense. I immediately started composing my post about this problem in my head, and after mailing myself a few notes, I returned to configuring OS X.
But while searching for something else on google later today, I found that someone had beaten me to the punch, and had already written up this OS X security issue much better than I could have ever hoped to:
In brief, Mac OS X’s NetInfo database stores crypted passwords that can be read by anyone with an account on the machine. Once the malicious user has the crypted passwords, all he has to do is sic a brute force cracking program on the hash until it finds a match.
To be fair, there is a way to secure your OS X box while still taking advantage of NetInfo as your primary configuration agent: You just need to make sure that your non-trusted users don’t have permission to run tools like NetInfo Manager or nidump.
But nope, the story in question doesn’t appear to be part of the tao at all. Though it really should be.
You know, I just realized yet another way that I’m a freak.
When I base a new password off of some dictionary word or phrase, instead of using 1337 sp34k s^b57i7u7i0n$, I use phonetic substitutions, based on the International Phonetic Alphabet where alphanumerically possible. I can’t honestly account for when I started doing this, but I guess it had to have been some time after I took Ling 100.
So I’ve been using some some shell scripts I hacked up to act like an ssh agent, but they were really kind of stupid, and would frequently force me to manually reset things after a reboot. But I’ve been alerted to a proper ssh agent login process someone a friend of a friend wrote. So if you use ssh on OS X at all, SSHAgentServices is for you.
Basically, I’m completely useless without UNIX. Back in the day when I was interviewed for the Sysadmin position here where I work, one of the questions was “What’s your favorite UNIX command and what’s an example of something clever you’ve done with that command?” Back then, I answered grep, but my clever answer was pretty lackluster, and more programmery than sysadminy. Which probably partially accounts for why I was hired as a programmer and not a Sysadmin, but at least I didn’t answer finger… Which one of my fellow rejected-for-sysadmin hired-for-programmers answered. ;-)
So without further ado, here are my five favorite unix commands, why, and maybe something clever I’ve done with each one.
- perl – Claiming perl as my favorite command isn’t really fair, since it slices and dices and is the ginsu of UNIX commands. Really, I don’t use `perl -e` all that often… But I use scripts starting with #!/usr/bin/perl every day, so that’s why this is number one. And being the shotgun it is, I’m not even going to try to give an example.
- wget – The very first problem I had with Mac OS X 10.1 was that they replaced wget with curl. I assume that curl is equally capable, but I happen to know all of wget’s switches back and forth, and I can recursively download a web tree or grab an mp3 in my sleep. I just prefer wget to download files to a web browser, because it’s easier to pick where I want the file to go, it’s more stable than a web browser, and the output is more useful. Any which way, a quick `wget url` is definitely my favorite method of downloading something.
- grep – I use grep any time I’m looking through huge hunks of text. From `tail logfile | grep -v “stuff I don’t want to see”` to `grep “email@example.com” ~/mail/*`, I basically use it as my first line search tool. My favorite use of grep was probably the time I was writing that paper on Dorian Grey, and I had a text file of the book. I was searching for references to opium, I needed context, so a simple `grep -A 5 -B 5 -i -E ‘opium|opiate’ doriangrey/* | enscript | lpr` gave me my pages of quotes just in time for my class.
- dict – There really aren’t any *clever* uses of dict, but I use it all the freaking time. For me, it doubles as both a spell checker and a dicitonary. Though now that I’ve been using Mac OS X a lot more, it’s just my dictionary, thanks to OS X’s integrated spell checking prowess.
- (gnu) tar – (gnu)tar is really the lynchpin of the Makefile for my sites. Mind you, it’s very important that that’s gnutar, because other tar’s just pale in comparisson. It’s mainly the –exclude filename (which excludes every file in the given file name) and –after-date date (which only includes files who were modified after the given date that make it so insanely powerful for me, and allows me to only upload things which have been changed since I started working with a simple `make` call to make.
Other top contenders included:
- make – I use make a lot, but really it’s just a way of making batch commands, and so for that reason it was dropped down.
- tail – In my line of work, I have to watch the log files from a lot of web servers, among other things, so I tail a lot of logs. But it’s really grep that makes tail so useful, because those are really verbose logs, and I know I don’t want to see everything in there.
- scp – This is what I use for 80% of my file transfers between servers (I use http for the rest), but it’s kind of boring.
- ssh – I have tendrils all over the place with ssh, but it, too, is pretty mundane. I still couldn’t get by without it.
- emacs/vi – I use both of these editors every day, and I really like both of them, but um, they’re kind of mundane.
What’re your favorite UNIX commands, and why?
I’m so amused by this perfectly correct, and yet so very undesirable crond behavior:
Date: Sun, 28 Oct 2001 01:59:00 -0700 (PDT) Subject: another nightly cron report Date: Sun, 28 Oct 2001 01:59:00 -0800 (PST) Subject: another nightly cron report
Well, looks like it’s time to start running that nightly report at some other time…