CSE 265: System and Network Administration

Lab #5

Today we look at logging, and a new scripting language (Perl).

  1. The tool /sbin/ifconfig can be used to configure or show the status of the network interfaces. The machines in the Sandbox lab are configured with two ethernet cards.

    One is typically attached to the departmental network. We usually leave the second (eth1) empty, for use in the future for networking-specific exercises.

    Running /sbin/ifconfig with no arguments generates a list of all network devices and their configurations. Note the list includes another device we have not mentioned -- the network loopback device, which is defined to be 127.0.0.1 for all systems, and is usually defined with the DNS name of "localhost". You can, for example, ping localhost with the same effect as pinging with the current name of your machine.

    Revise the local boot script from lab #2 to incorporate the output of ifconfig on every boot.

  2. In this exercise, we will use the Perl scripting language to replace the logger(1) command. To start, try out the logger command by typing "logger hello" and then use tail on /var/log/messages to see your log entry.

    If you are unfamiliar with Perl, start by skimming through a Perl tutorial. If you are uncertain of your programming skills, I suggest: Picking Up Perl. If you are more confident, try Perl in 20 pages.

    There is lots of Perl documentation online and there are three books on Perl (such as Learning Perl and Programming Perl) in the Lehigh Safari e-book library, including a relatively advanced book on Perl for System Administration. (Chapter 9, Log Files is also available separately.)

    Now write a very simple Perl script that prints out the parameters given to it, like the echo(1) command. It should work like this:

    % ./echo.pl hello
    hello

    The following script will write the words 'hello world' to syslog, along with the PID of the logger.pl process. Modify it to write the contents of all parameters of the script instead (like the echo script above).

    #!/usr/bin/perl
    
    use strict;                              # compile-time checks
    use warnings;                            # enable run-time warnings
    
    use Sys::Syslog qw(:DEFAULT setlogsock); # library for syslog functions
    
    setlogsock('unix');                      # use a unix domain socket
    openlog("logger.pl", 'pid', 'user');     # register ourselves
    syslog('info', 'hello world');           # the syslog call
    closelog();                              # close the socket
    
    Verify that it works by running it and checking /var/log/messages.

Consider using any remaining time in lab to work on project #1.

In order to sign the lab completion sheet, you will need to:

  1. demonstrate your perl script by running it with a multi-word message and seeing the effect on /var/log/messages.
  2. Show /var/log/network-startup.log containing ifconfig data.


This page is http://www.cse.lehigh.edu/~brian/course/2008/sysadmin/labs/lab5.html.
Last revised: 13 February 2008.