February 16th, 2006 | Tags:

One of my clients purchased a dedicated server with 2 hard drives (very common configuration these days). Unfortunately their provider can’t/won’t configure their server to use software raid. My suggestion was to use the 2 matching drives in a software raid-1 configuration, but I’ve never remotely setup software raid after a server was already up and running.

Warren Togami provides a very detailed howto on remotely migrating 2 matching hard drives running Linux to a software RAID-1 configuration:
http://togami.com/~warren/guides/remoteraidcrazies/

This server was running RHEL4 and the above process worked great for me. I do have some notes that I’ll be sending back to Warren:

  • Step 5) My first drive was setup to use 255 heads whereas hdc was configured to use 16. I ran “sfdisk -H 255 /dev/hdc < partitions.txt" instead of "sfdisk /dev/hdc < partitions.txt" to reconfigure the 2nd disk to use 255 heads just like hda.
  • Step 25) Shouldn’t the commands for hdc be referencing (hd1) and (hd1,0) (where appropriate)?
  • Step 26) It says to most importantly change the root setting back to (hd0,0), yet the example still shows (hd1,0).
  • Step 27) Attempting to run “mdadm -A -s” resulted in a “mdadm: No arrays found in config file” error message. I was able to get rid of this error by creating /etc/mdadm.conf as listed in Step 22 (even though it says RHEL4 no longer requires that file, it seemed to help out in my situation).

Without Warren’s document it would have taken me much longer to figure out the best way to get this done remotely. I’m usually spoiled in that I have hardware raid on most machines and get to partition things just as I wish when I install them on-site.

February 7th, 2006 | Tags:

http://www.cs.usfca.edu/~parrt/course/601/lectures/unix.util.html

Here’s a very useful set of instructions that every developer that deploys on unix/linux should know.

“If you want to be a serious server developer, you will need to have a certain facility with a number of UNIX tools; about 15. You will start to see similarities among them, particularly regular expressions, and soon you will feel very comfortable. Combining the simple commands, you can build very powerful tools very quickly–much faster than you could build the equivalent functionality in C or Java, for example.”

My favorite of all the commands mentioned is rsync. I use it daily to move things around between servers and even on the same machine. I’ll discuss rsync and how I use it later.

Comments Off
January 26th, 2006 | Tags:

When writing shell scripts I often need to both run the scripts manually during the day and also have them run via cron at night. I frequently log the output of the shell script to a file to reference later and email the log file.

Referred to as a pipe fitting program in its man page, tee will allow you to copy STDIN to STDOUT and display it to both the screen and a file. I’ve included a short script as an example:

#!/bin/sh
echo "Hello World!" | tee file.log

You’ll find the output Hello World! on both the terminal and in file.log. You can also tell tee to append to the file with the (-a) option. Without it you would continually write over the file with the latest output you wanted to log.

It took me a while to discover the tee command but I’ve been able to put it to great use when writing scripts that I’ll run both manually and from cron.

December 22nd, 2005 | Tags:

Time to break my habit of using crontab -e. As we all know this opens our default EDITOR and allows us to quickly edit and save our cron jobs. This is a huge risk. If, for example, you find yourself logged in on a strange system and EDITOR is set to something you don’t know, you’re much more at risk to accidentally erase your crontab.

The proper way to edit your crontab is as follows:

crontab -l > /tmp/mycrontab
vi /tmp/mycrontab
(make your changes)
crontab /tmp/mycrontab

Feel free to put the mycrontab file in your home directory (I just used /tmp as an example).

By following the above process you are creating a backup of your crontab and you have full control of the editor you will use to make your changes. You’ll thank me the next time you mistype and enter crontab -r (-r: Remove the current crontab) instead of the crontab -e you thought you typed.