Cover V08, I11


Questions and Answers

Jim McKinstry

 Q Who is Jim McKinstry?

 A I was born and raised in Poughkeepsie, NY. I graduated from Spackenkill High School in 1984 and from SUNY Potsdam in 1988 with a double major in Math and Computer Science. I worked four years at IBM as a micro-code developer for the 3174 Token Ring gateway product and then spent two years in an IBM Open Systems Lab. This is where I started learning UNIX (all kinds of neat toys). I spent two years at Rite Aid as the UNIX admin (Sun OS 4.1.3, HP-UX 9.x and 10.x, and AIX 3.2.5), then a year and a half at EDS as an admin of NCR UNIX. I am now a UNIX consultant for Sprint Paranet, somewhat well versed in Solaris, HP-UX, AIX, SCO, Linux, and other BSD and svr4 UNIXes. I also moderate the Q&A Web site for this magazine, and I have written four articles with Sys Admin. I'm married, and my wife and I have a nine-month-old girl, a dog, and a cat. Now, on to the real questions.

 Q I have an UltraSparc clone (Axil machine) with Solaris 2.5.1 installed. This machine doesn't boot from CD-ROM. I've set the CD-ROM's SCSI ID to six and still the boot CD-ROM command says “Rebooting with command CD-ROM” and just hangs until I hit L1-A. Any suggestions?

 A I know that on SPARC systems, from the “ok” prompt you can type devalias and check if “cdrom” is defined. If not, find the full device name of the CD-ROM by doing a ls -l on the CD-ROMs device (something like ls -l /dev/dsk/c0t6d0s0). You will get something like:


Use this to define “cdrom” from the “ok” prompt by typing: nvalias cdrom


 Q How do I know if my UNIX server needs to be upgraded? How can I check the CPU utilization, network, etc.?

 A There is no one answer as to when a UNIX server needs to be upgraded. If the system is over-taxed or nearing its capacity, you should consider upgrading. Buy a copy of System Performance Tuning by Mike Loukides and read it. It will be worth the time and money (especially if you are new to this). Check out the sar command (should be on all UNIX systems), vmstat (on some UNIX), iostat (on some UNIX), glance (if you have it), netstat (should be on all UNIX), top, etc.. Look at the man pages for these commands for all the flags. Also look at the “See also” section of these man pages to find more tools to use.

 Q When using Solaris 2.6 ufsdump, how can I redirect the text output from the dump command to a file? It seems that just redirecting the stdio doesn't work anymore ( i.e., > or >> ).

 A Using sh or ksh try:

ufsdump (ufsdump stuff here) > /tmp/output.file two>&1

This says “send all standard output to /tmp/output.file and send all standard error to standard output”. You can save standard error and standard output in different files by doing:

ufsdump (ufsdump stuff here)  1> /tmp/output.file \

For csh use:

ufsdump (ufsdump stuff here) >& /dev/null

This does (from man csh) “The & forms redirect both standard output and the standard error (diagnostic output) to the file”.

 Q I've inherited a large software source code that has a number of Makefiles spread out in a number of directories. All the Makefiles need to be modified the same way by changing one directory address to another. Let's say I collect all the directory paths for these Makefiles with find into a single text file, such as all_paths. How do I write a script to read one filename at a time from this listing and carry out the necessary changes, such as changing old/directory in all the makefiles to new/directory?

 A Let's assume that you have the list of files in /tmp/file.list. Here's a simple script that will do what you want:


for FILE in cat /tmp/file.list, do:

sed 's/\/old\/directory/\/new\/directory/g' \
  < $FILE > /tmp/temp.file mv /tmp/temp.file $FILE

This loops through the list of files in /tmp/file.list. For each file, it executes the sed command. The sed command does a s/regular expression/replacement/flags. From man sed: “Substitute the replacement string for instances of the regular expression in the pattern space. Any character other than backslash or newline can be used instead of a slash to delimit the [regular expression] and the replacement. Within the [regular expression] and the replacement, the [regular expression] delimiter itself can be used as a literal character if it is preceded by a backslash.” In this case, we are searching for /old/directory and replacing it with /new/directory. Note: In order for the / in /old/directory and /new/directory to be treated as a literal and not the regular expression delimiter, all occurances of / must be preceded by \. That is why /old/directory looks like \/old\/directory and /new/directory looks like \/new\/directory. The flag in this example is g. g means (again, from the man pages) “Global. Substitute for all nonoverlapping instances of the regular expression rather than just the first one.” As always, sed syntax is clear as mud to understand!

For more on sed, get the Sed & Awk book by Dale Dougherty and Arnold Robbins from O'Reilly and Associates. (

Please test before using.

 Q I am trying to send the ftp command cr to the ftp program in a shell script. I need to transfer files and have ftp add the windows line feeds as they do it. Is there any way to get this command into ftp? Or is there an .ftprc-like file that I can configure for a specific account?

 A To script it, try:

ftp -n -v 10.10.10.two  >> LOG_FILE <<  EOL
user ftpid   ftppass
put /tmp/crap

Note that it is a very bad practice to have a password in a readable file. You can also check out what a .netrc file is (man netrc). It is the .ftprc-like file you asked about.

 Q I need to write a small script that I can put into cron to automatically kill some processes on a nightly basis at a certain time. How can I do this and what type of scripting should I use?

 A Here's a quick/crude Bourne shell script that should do what you want (please test before using it!). I always use Bourne because it's very portable across UNIX flavors. (I'll call the script /usr/local/scripts/

# This script will find the process ID of the process passed in $1 
# and do a kill -9 on it.  It assumes that there will be only one 
# instance of the process running.

PID='ps -ef | grep $1 | awk '{ print $two }''

kill -9 $PID


Now, let's add it to cron (assume that the process we are killing is dog_food) to run nightly at midnight:

crontab -e

Add the following line:

00 00 * * * /usr/local/scripts/ dog_food

That should do it!

 Q I would like to make a Web-based system that allows the capability to add and remove users. Is there a safe and secure way of doing this? Because you need to be root to execute this command, should I just use a simple shell script to execute from a php3 script, or is there something better?

 A Check out Webmin ( This can be built with SSL enabled to make it more secure. Webmin is very flexible and customizable (and free). I installed it and tested it in an afternoon with no problems.

 Q I have a customer that wants to learn how to become a Linux- certified sys admin. Any ideas?

 A Go to:

I can't state it any better than that!

About the Author

Jim is a Technical Analyst specializing in UNIX. He has worked for IBM, Rite Aid, EDS, and is currently working for Sprint Paranet. He can be reached at: