Linux Project

Apache, shell scripts, cron
Thursday, 31 Jan 2002

Apache.Test your Apache web server by launching Mozilla and typing "http://localhost/" into its URL window. Chances are you will get an unsatisfactory result. To instruct Apache to begin accepting requests for web pages, open emacs (as root) on /etc/httpd/conf/httpd.conf and scroll down to the line which reads #Servername localhost. (Use the emacs Search facility to do this). The "#" at the beginning of the line means that this line has been commented away, so Apache does not know an appropriate ServerName. To limit Apache's reach to your own machine, for instance, for development purposes, just erase the "#" and save the file. To open up Apache to the world, replace the word localhost with the IP address of your machine. You can discover the IP address of your machine, or any other, with the host command.

# host pluto has address

Once the correct IP address is at hand, enter the appropriate line into the Apache configuration file:


We are now ready to launch the Apache web server. First, verify that it is not already running.

# ps -ef | grep httpd

You may well see only two lines, one representing the emacs httpd.conf process and the other the grep httpd command. Launch Apache.

# /etc/init.d/httpd start

Incidentally, /etc/init.d/httpd is the standard way to manipulate the Apache server. Type that command with no arguments to see your choices.

# /etc/init.d/httpd

If the httpd daemon had already been running, we would have typed

# /etc/init.d/httpd restart

after modifying the Apache configuration file to begin using the new configuration. Now use ps (process show) once again to see what changes might have taken place.

# ps -ef | grep httpd

You should see quite a few of those little daemons sitting around waiting for web page requests. Go back to Mozilla and try connecting to your web server once again. If you see an Apache Test Page, your server is working. Congratulations!

The web pages to be served by Apache all live in /var/www/html, as does the Apache manual. Rename /var/www/html/index.html to something like /var/www/html/index.html.bak and introduce your own index.html to begin serving your own web pages. Apache already knows all about diving down into local directories for more pages, and the like. Chances are you won't need to further reconfigure Apache unless you decide to do something pretty exotic.

Shell Scripts. We all find it convenient from time to time to work on remote machines. Read the section on telnet in these instructions to recall how this is done, and then telnet to a remote machine and use emacs to modify some textfile on that remote machine. We can automate this process somewhat by writing a couple of shell scripts. On your local machine, open emacs on the (new) file xhosts+ in your home directory and type in this line:

/usr/bin/X11/xhost +

Save the file, and make it executable.

chmod +x xhost+

List your directory to verify that it is now an executable file.

ll .

The "." means "this directory." You should know how to read the file protection codes that ll displays.

Now we need a matching file on the remote computer. Suppose that your local machine is named pluto. On the remote machine, open emacs on the (new) file exportPLUTOdisplay in your home directory on that machine, and enter the following line:

export DISPLAY=pluto:0.0

Save the file, and make it executable.

chmod +x exportPLUTOdisplay

List that directory to verify that exportPLUTOdisplay is now an executable file.

It is now a bit smoother and simpler to work on that remote machine. First, in the home directory on the local machine, type


Then telnet to the remote machine and type

and you will then be using your local monitor to display processes generated on the remote machine. This is just a small demonstration of the utility of shell scripts. The next section illustrates another application.

Cron. All clocks drift, even computer clocks. But we live in the age of amazingly accurate atomic clocks, and your computer is only a remote command away from a time server with access to such a very accurate time source. Open emacs on the (new) file rdateCMU in the directory /etc/cron.daily and type in the following lines:

if rdate -s; then
   /sbin/hwclock --systohc

Make this file executable.

chmod +x rdateCMU

To reset your computer's clock right now, execute this file.


Since it is in the directory /etc/cron.daily, the cron process will automatically execute it once a day and your clock should keep pretty accurate time. Just to check it, open Mozilla on the web page for the Official US Time, and click on Tennessee. You should see an interesting display of the world, an accurate approximation of the time in your locality, and even an indication of just how accurate that displayed time may be.