Viewing the differences between two directories on Linux servers

This past week I needed to compare the contents of two directories to see if there were any differences. There are a TON of ways to do this, though my preferred way is to use diff with the “-r” (when comparing directories do so recursively) option to compare two folders:

$ find foo1

$ find foo2

$ diff -r foo1 foo2
Only in foo1: services2

Simple, easy and it gives you the output you’re most likely after. Anyone found a simpler solution that this? :)

Conditionally restarting Linux services

Periodically I need to start a service, but only if it’s not currently running. Other times I need to restart services on a machine, but only if they are currently running. Services may have been started on the system at boot, manually by an admin, or through a systems wide management infrastructure. They may also have been disabled on a server for one reason or another. Most Redhat Linux rc initialization scripts have a “condrestart” target to help facilitate conditionally restarting a server, which can be useful when you need to conditionally start services across dozens of machines.

The conditional restart logic is usually implemented as a test similar to this (I took this from the dnsmasq init script):

    if test "x`pidfileofproc dnsmasq`" != x; then
	$0 stop
	$0 start

This allows the script to restart the service if it’s currently running, but you could alter this behavior to start or restart a service if it’s not running (you can get a bit more fancy and check the result of pidof to see if the process is indeed running):

     [ ! -e /var/lock/subsys/myservice ] && stop && start

This isn’t something you will use every day, but it’s rather handy when you need it. It also helps to know what will happen when you use the “condrestart” logic baked into various system init scripts. If you develop init scripts for services other than the defaults that ship with CentOS, Fedora or RHEL Linux, you may be interested in this!

System management tools

When I was studying for my RHCE exam, I came across a number of references to Redhat’s satellite server and its opensource spacewalk counterpart. To dig into these products a bit more, I recently attended Redhat’s deployment and systems management class. I’ve been using satellite server for the past two years, and it’s actually a really useful tool for managing configuration data and systems updates in data centers that solely run Redhat Enterprise Linux. Satellite server provides a number of handy features:

– Patch management (reporting and applying updates to servers)
– Configuration management (versioning and pushing configuration data to servers)
– Monitoring (basic system-level monitoring)
– Provisioning (provides a nice GUI that front-ends kickstart / cobbler)

The commercial version of satellite server will set you back some serious cheddar, but luckily for us satellite server is based off the spacewalk opensource implementation. Spacewalks seems to have a pretty decent following, and it provides an easy way to manage CentOS and Fedora machines.

There are roughly a dozen systems management products that I want to test out this year, several of which are wrappers around puppet. Once I give spacewalk a good beating, I am going to shift gears and start looking at The Foreman. The Foreman appears to have everything I’ve been looking for in a configuration management and provisioning suite, and the fact that it can provision Solaris hosts intrigues me. Only time will tell if it works though!

Which packages or tools are you using to manage (provision, configuration management, monitor) your Linux hosts?

Retrieving a bunch of files with wget

I periodically need to retrieve new CentOS and Fedora releases. Sometimes I need to snag CDs (I still support machines without DVD drives), and in other cases I need DVDs. Typically when I’m playing around with new releases I grab both, and use the wget to retrieve them all at once. If you pass wget a FTP URL that contains a *, it will retrieve all of the files in the directory you are retrieving files from. Here is an example:

$ wget ftp://foo/pub/centos/5.6/isos/x86_64/*

This will grab all of the files in the x86_64 directory and place them in the current working directory. You can also disable prompting and use the mget command with your favorite FTP client, but I find wget to be a bit more versatile since you can use the “-c” option to continue failed transfers. What is your favorite method to retrieve files?

Locating your Dell service tag without openmanage

Dell provides the openmanage suite of tools to monitor and report on the hardware in their servers. I’ve managed a few hosts in the past where openmanage wasn’t installed, and I needed to locate the service tag so I could get the hardware in the server serviced. Luckily for me the dmidecode utility was installed, which will print the SMBIOS data that was burned in by Dell at the factory:

$ dmidecode |more

Handle 0x0100, DMI type 1, 25 bytes
System Information
        Manufacturer: Dell Computer Corporation
        Product Name: PowerEdge 1650             
        Version: Not Specified
        Serial Number: ABCDEFG
        Wake-up Type: Power Switch

The “Serial Number:” value contains the service tag number of the server, and it should match up with the value in the BIOS as well as the one on the tag that is on the back of your server. So if you manage a Dell server that doesn’t have openmanage installed (and more importantly the omreport utility), dmidecode and lspci should make you very very happy. :)