UNIX Tool Chest

—by David O’Donnell, atropos@afp548.com

25 September 2002—Updated 30 September 2002

Mac OS X Server is the closest thing to the “perfect” melding of graphical user interface and UNIX power, at least to my mind. A GUI isn’t everything, though; sometimes it is better, faster, or just easier to drop down to the command line to perform a task. This article—which is a work in progress—highlights some of the UNIX tools I find indispensible. Please let me know if you have any tools that you use frequently but don’t see mentioned here!

Lynx

There are half a dozen Web browsers available for Mac OS X, but only one can run in the command line. Lynx (currently at release 2.8.4) is available for many distributions of UNIX and Linux, and compiles cleanly under Mac OS X. Lynx is indispensible for testing Web sites under limited conditions or checking suspicious HTML code for Web bugs and other nasty marketer tricks. Lynx can also be used to retrieve Web pages, sites, and files without incurring the overhead of a GUI browser.

To install Lynx, create a directory where its source code will exist and execute the following commands at the Terminal prompt:

curl -O http://lynx.isc.org/release/lynx2.8.4.tar.gz 
gnutar zxvf lynx2.8.4.tar.gz 
cd lynx2-8-4 
./configure 
sudo make 
sudo make install 
rehash

NcFTP

Apple included a version of NcFTP in previous distributions of Mac OS X, but it has gone the way of wget in Jaguar. It may be due to NcFTP’s lack of SSH support, but regardless of the reason NcFTP is a great FTP tool. NcFTP can save places you visit in bookmarks and—perhaps its greatest asset—it supports command-line recall. The folks at NcFTP Software have built a Package Installer release of NcFTP that you can retrieve here. Download, unpack and open the Disk Image, then double-click on the Package to install the software. Remember to issue the rehash command from the Terminal if you have a command line session open while installing!

Fink

The Fink Project is an ambitious effort to provide a large repository of Open Source UNIX software for Mac OS X. My hat is off to their developers for the time and effort they put into providing libraries, X Windows, and much more. I used Fink extensively under Mac OS X and Mac OS X Server 10.1.x. The Fink development team hasn’t completed certifying their distribution for Mac OS X 10.2 just yet, but the bulk of their offerings are at least semi-ready.

Fink provides an amazing array of packages, but not all are appropriate for all situations, so be wary when picking what to install. Start with something innoccuous, like the package to update basic command line tools like ls. Fink isn’t always up to date when compared to actual packages, either, so if you find something that you want to install make sure to see if the original source has a newer version.

Ipresolver

UNIX is all about tools that do one thing well, and keeping that in mind, I hobbled together a little script that takes an Apache log file, resolves IP addresses to domain names, and writes out the results in a gzipped file for later processing by Analog and Report Magic. Ipresolver is useful to me because it gets around the bug in Apple’s memory management code that prevents Analog from doing the lookups itself, and because it makes an otherwise repetitive task much easier. Ipresolver has to be run as root, and it makes a simplistic check to ensure you are before proceeding. The source of this script is included for your enjoyment, below. Please contact me with corrections or improvements!

#!/bin/sh

# Are we root?
echo "user"$USER"user" > /tmp/foobarbazbash

if grep "^userrootuser" /tmp/foobarbazbash > /dev/null;
then
echo 'Resolving IPs for logfile: '$1
/usr/sbin/logresolve < $1 > $1.resolved
rm $1
mv $1.resolved $1
gzip $1
echo 'Done.'
/bin/ls -alF $1.gz
else
echo "** You are not superuser. Quitting."
fi

rm /tmp/foobarbazbash

If you have a lot of log files (as we do), I find the following command line to be helpful in concert with this script:

ipresolver `ls $LOGNAME.* | grep -v gz` ; ls -alF $LOGNAME.* | grep -v gz

Replace $LOGNAME with the root of the logfile names (for example, 'AFP548-access-log'). The command grabs the first entry in the list of non-gzipped logs and feeds it to ipresolver for processing, then prints out a list showing the remaining ungzipped logs so you know how many logs are left to resolve. Remember to leave the last one unresolved, as that is the current open log. There are certainly better ways to do this, but this way works.

Aringet

One of the things every Internet citizen has to deal with is that most odious of crap, spam. I’m not talking about Hormel’s product that you can buy in the shops, but the incessant deluge of unsolicited commercial e-mail that unscrupulous marketers, pornographers, politicians, and self-styled “entrepreneurs” are determined to foist upon our mailboxes. Spam is an infection that threatens to turn terminal, and it is the duty of every Internet citizen to help stamp it out. In addition to never patronizing any business that spams; and advocating for local, regional, national and even international laws that make spam illegal (and actionable!), you should track down and report every spammer who slimes your INBOX.

The aringet script, which I include below, helps you track down spammers by retrieving information from the ARIN servers. You could do this by executing whois -h whois.arin.net string, but ARIN returns more information than is strictly necessary. This one-line script uses the curl tool to strip away the fluff and only return the important bits. Thanks for its inspiration and original inception go to John Levine, one of the many tireless anti-spam admins on the Internet.

#!/bin/sh
curl --silent “http://ws.arin.net/cgi-bin/whois.pl?queryinput=$1” \
| sed -e '1,/<pre>/d' -e '/<\/pre>/,$d' -e 's/<[^<]*>//g'