-
-

Menu
Home
-
ASCII Character Set
-
Beatles Programmers Album
-
Change UNIX Password
-
Color Tester
-
Free CGI Scripts
-
HTML Tag List
-
Internet Explorer Bug
-
ISO-Latin-1 Character Set
-
Links
-
Managing Shell Utilities
-
Netscapes Bad Rap
-
PDF Maker
-
Please Your I.T. Dept
-
RGB to HEX Converter
-
Server-Side Includes
-
Technical Books
-
UNIX man Pages
-

-
Scott Crevier's Webmaster Resources
Managing UNIX Shell Utilities

I've been making some of my shell utilties available for download for some time now. For the most part, they work just fine as is. But there is a general question that is asked of me quite often. "So I've downloaded your script, how do I run it?"

This document will explain to you the logistics of downloading, installing and running UNIX shell utilties. You will notice that several times I will mention certain specific shells as well as the process of editing text files. I hope the you are a little familiar with these, as these issues are beyond the scope of this document.

UNIX vs DOS

Many people think that comparing UNIX and DOS is a cardinal sin. Well, I agree to a certain extent, however, for purposes of this discussion, if you are familiar with certain DOS features, it will help you understand certain UNIX features.

When you enter a command at a DOS prompt (C:\>), DOS looks for that program in the directories that are indicated in your PATH environment variable (some commands are also internal to the operating system but that is not important right now). If the program is not found in one of those directories, you get a message like "Bad command or file name".

The PATH Environment Variable

UNIX searches for commands just like DOS. Many UNIX programs are stored in the /usr/bin directory. Others are in /usr/local/bin. And still others may be found in other directories. To see which directories are in your PATH environment variable, enter the following command:

$ echo $PATH
(The first $ in this command represents the shell prompt. Don't enter that.)

The directories shown (separated by colons) are those directories that contain all the shell programs that you can run. Go ahead and 'cd' to the /usr/bin directory and see what programs are there. You'll probably find over 300, like grep, vi and more.

Your Own Personal 'bin' Directory

So, how does this knowledge help you setup your own shell utilities? Well, you simply need to duplicate the above setup. Follow these steps:

  1. In your home directory, create a new directory called bin. For example, my home directory is at '/u3/home/crevier' so my bin directory is at '/u3/home/crevier/bin'. The name bin (short for binary) is a name commonly used to indicate directories that contain executable programs/scripts.

    $ cd         (cd with no arguments always takes you to your HOME directory)
    $ mkdir bin

  2. Now we need to modify your 'PATH' environment variable that we discussed earlier, so that this new directory is included there. The file that you make this change in will depend on which shell you are using. If you use the Bourne or Korn shells, you will need to modify your '.profile' file found in your home directory. If you use the C shell, you need to modify the '.cshrc' (short for C Shell Run Commands) file also found in your home directory.

    The actual modification you make, again, will depend on which shell you are using. The easiest thing to do is to look for a line that looks like this:

          PATH=/bin:/usr/bin:/usr/local/bin:.

    and change it to this:

          PATH=/bin:/usr/bin:/usr/local/bin:$HOME/bin.

  3. Now, to make this change take affect, you will need to log out and log back in, or just run your '.profile' file or '.cshrc' file manually. Remember, you can use the "echo $PATH" command to verify the contents of the variable.

Does It Work?

Now, let's test the above setup to make sure it works. Go into your new bin directory and create a shell script called la. You'll need to use a text editor to do this. I use vi. You could also use pico or you could even create it in Notepad and ftp it if you want (although, using Notepad isn't always a good idea, since it adds an extra character to the end of each line, and a UNIX shell won't understand this). Whatever your preference, create a script that contains the following two lines:

#/bin/sh
ls -la | more -e

Set the permissions on this file so that you can execute it.

$ chmod 700 la

Now go to any directory anywhere and enter the la command. Once you've got that working, you can see that it is possible for you to create more of your own utilties. For example, if you frequently run a command that analyzes your web log files, put that command with all its arguments into a shell script in your bin directory and name it 'webstats'. Now you can just run the 'webstats' command without having to remember all the command line arguments. Or you could add your new 'webstats' command to a cron job that runs every night.

Using Other People's UNIX Utilities

So, with this arrangement all set up and working, it is quite easy to implement utilities that you get from someone else, like the ones that I've written. Just download the utility, put it into your bin directory, set the permissions to 700 and you're all set.

Just a word of caution though, about using utilities that you did not write yourself. For your own sake, be sure to read through any script that you download and make sure you are comfortable with the commands that it is running. Obviously you should watch out for the rm command and other commands that could do you harm.

But you should also look for variable settings to see if certain variables need to be customized for your environment. For example, you might find a variable that is set to the path of your temporary directory or your home directory. If such variables are already set in the script, make sure that they are valid values on your system.

Recommended Reading

The following titles will provide more formal instruction on some things that I've mentioned, like running different UNIX shells, editing text files, using the UNIX cron and setting environment variables.

Learning the UNIX Operating System, by John Strang, Jerry Peek, Grace Todino
UNIX in a Nutshell, by Daniel Gilly
vi Editor Pocket Reference by Arnold Robbins

05-Jan-1997



-
smcNet Copyright © 1997-2024 Scott Crevier
www.webmaster.crevier.org
De Pere, Wisconsin, USA
Powered by Perl