About A.P. Lawrence

A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com
Rebuilding failed Linux software RAID

Recently I had a hard drive fail. It was part of a Linux software RAID 1 (mirrored drives), so we lost no data, and just needed to replace hardware. However, the raid does requires rebuilding. A hardware array would usually automatically rebuild upon drive replacement, but this needed some help.

Handling Missing Data in Inputs

Missing data can be very annoying to a programmer. In fact, it is so annoying that very often we’ll write separate programs to clean up data and eliminate unpleasant conditions so that the main program doesn’t have to deal with it. Here, I’ll show some examples of the kind of problems we see.

More Perl Sorting

Perl has an easy to use “sort” function. For example, you might have an array like this:

How “ps” Works And Why

The simple “ps” command has generated a fair amount of confusion. Almost every Unix variant does it slightly differently; flags have different meanings and column headers or position also differ. This wreaks havoc with cross-platform scripts and has also caused bitter comments now and then. As I explained at I_WANT_A_BROKEN_PS , I had the same misunderstandings. Albert Cahalan (author of the Linux procps package, which includes “ps”) noticed a newsgroup thread where I had made such a comment, and took the time to reply to me. After reading his explanation, I understand that I was quite wrong.

Two Safari’s

Look carefully at the image below. You see two Safari icons in the Dock (one third from the left, the other next to the app/doc divider), and also two Safari browsers open, both on the same site and page, but displaying very differently. The Font preferences are also shown, and this is what makes them different.

Perl Sorting

Arrays often need sorting. Perl has built-in ways to help you, but as usual, there’s more than one way to do it.

To play with the examples shown here, you’ll need a file containing a few lines of words. I’ll use this:

Understanding Floating Point Formats

Under ordinary circumstances, you don’t have to know or care how numbers are represented within your programs. However, when you are transferring data files that contain numbers, you will have to convert if the storage formats are not identical. If the numbers are just integers, that’s fairly easy because the only differences will be the length and the byte order: how many bytes the number takes up, and whether it is stored lsb or msb (least signifacant byte or most significant byte first). Once you know that, conversion is trivial.

Recovering System After Upgrade

Usually upgrades are binary: either they work or they don’t. Actually, my experience with SME upgrades has been very good: I’ve only had a very few where the upgrade process didn’t work at all. In those cases, you install new, apply all applicable blades, and then restore from backup. That’s annoying, but fairly simple.

Getopt and Getopts

Both “getopt” and getopts are tools to use for processing and validating shell script arguments. They are similar, but not identical. More confusingly, functionality may vary from place to place, so you need to read the man pages carefully if your usage is more than casual.

Transferring to New Hardware With a Supertar

With any of the Supertars, transferring to new hardware is easy. If the new hardware uses the same disk controller (or the same driver) as the old, you can just boot from your recovery media and proceed to recover the system. But what about when the new hardware is different?

SME Server Local Networks and VPN’s

The SME Server (formerly E-Smith) normally rejects attempt to send mail outside of its own domain if you are connecting from somewhere other than the local lan. This is correct behaviour; otherwise anyone could use your server as a mail relay and you’d become an inadvertent spammer rather quickly.

Neglect and Misunderstanding of Backups

I had a call this week from a client who needed a file restored from backup. I had set them up with DVD-RAM and a Supertar a year ago, and had labeled five cartridges with Mon, Tues, etc. I know that (or thought I knew) they followed this rotation for a while, because I had used the previous day’s backup to restore files for them earlier this year.


Xinetd is a replacement for inetd, which was the original Unix super-daemon used to start network services on demand. The reason for inetd goes back to days of low memory and poor memory management: you didn’t want to keep a service running in memory if it was infrequently used. One process (inetd) would listen for connections on appropriate ports, and fire off the appropriate service when a request came in.

Kerio Mail Server

The Kerio Mail Server is a cross platform ( Windows, Linux, and Mac OSX) mail server. I tested it on RedHat Linux 8.

MacOSX lookupd and NetInfo

Changing Name Resolution Order

Name resolution is how your system figures out the actual IP address for host.xyz.com (and vice-versa). For most Unix systems, that function is provided by “named” and the configuration files are /etc/resolv.conf, named.conf, and perhaps nsswitch.conf. While you’ll find a resolv.conf and even a named.conf on Mac OS X, you won’t find named in the process list. Instead, MacOSX has a neat resolver capability controlled by “lookupd”.

Tightvnc, Chicken of the VNC

VNC is “Virtual Network Computing” and is a crossplatform method of allowing remote access to desktops (Windows or Unix/Linux, Mac and others)). It is conceptually like using Terminal Services or PcAnywhere etc for Windows but is license free and of course capable of serving Linux/Unix machines also.

Random Numbers

Random numbers are important for computers. Aside from making games like Solitaire more interesting, the use of randomness in generating passwords and encrypting data is critical to security.

Python vs. Perl

Perl folk seem not to like Python, at least not at first glance. It’s easy to understand why: the languages serve similar purposes, but have annoyingly different syntax and structure. There have been converts, though, and Eric S. Raymond’s experiences are probably not atypical.

Lost Root Password (Linux)
· 3

I have a very good memory. I remember most of my client’s passwords (there are a few I forget regularly for no reason that I can understand, but I really do know most), I remember telephone numbers, and of course I know my own passwords. That last isn’t as easy as it might sound, because I have quite a few different systems and each has its own password, but though I might use the wrong one now and then, I’ll get it on the second or third try.

Securing POP mail access in MacOSX

I always worry about my website. Security is serious stuff, and you really can’t be too careful. I don’t enable telnet, rlogin and use long, complicated passwords with ssh and so on. I use a shared webserver (http://www.interland.com) that allows me virtual root access, and I fortunately don’t have to worry about things like sendmail; Interland keeps on top of that sort of thing for me.

Perl Input

Perl has wonderful I/O capabilities. I’m only going to cover input here: reading from files or standard input. There are two ways to do that (actually a lot more than two, but this is supposed to be introductory material): you can open a specific file, or you can pass files on the command line and either open them individually or just ignore the whole thing and pretend everything is coming from STDIN.

Numeric Unix Error Messages

It’s an unfortunate fact that many programmers are lazy about error messages. Very often, all you get is a cryptic “Error 5″, and you may be lucky to get that: sometimes all you get is an error return that you have to examine yourself with “echo $?”. You can’t even depend on that being the actual Unix error, but even if it is, what does it mean?

Mac OS X Panther upgrade

A lot of folks have grumbled about paying $130.00 to upgrade to Panther, the latest version of Mac OS X (October 2003). I have to say that it is definitely worth it: maybe you feel cheated because you just paid for Jaguar six months ago, but you will be happy after you install this. The hype, for once, has reality behind it: this is as good as Apple said it would be.

Fork and Exec with Perl

Recently I had a project that required a number of different programs that will mostly run all the time, but need to be restarted now and then with different parameters. Normally, the first thing I think of for a program that runs constantly is inittab or svc (daemontools). The svc facility is the more flexible of the two, and will be what I’ll use in the final design, but in the “thinking” stages I played with using a Perl program launcher and controller.