#!perl/bin/perl

# logs1.pl
#
# A Perl script to read, extract, and print a log file from
# the Sambar Web server.
#

# Put the log file name into a local variable -- full path.

    $LogFile = "c:/sambar/logs/access.log";

# Open the file; die if that's not possible.

    open (LOG, $LogFile) || die "Can't open $LogFile: $!\n";

# Read, extract, and print each line from the log file.

    while (<LOG>)
        {
        $LogLine = $_;            # Store the line locally.

    # Strip out the characters we don't need.

        $LogLine =~ s/\[|\]|\"//g;
        chop ($LogLine);

    # Extract the components using split()

        ($ClientIP, $Dummy, $UserName, $DateTime, $TimeZone, $Operation,
            $Target, $HTTPVers, $SrvrStatus, $NTStatus,
            $BytesXfer) = split (/[ ]+/, $LogLine);

    # Print the values to the screen.

        print "Client's IP address = $ClientIP\n";
        print "Name of user on client = $UserName\n";
        print "Date and time of request = $DateTime\n";
        print "Operation requested = $Operation\n";
        print "Operation target = $Target\n";
        print "Server returned status of $SrvrStatus\n";
        print "Windows NT returned status code $NTStatus\n";
        print "Transferred $BytesXfer bytes of data\n\n";
        }            # End while (<LOG>)

    close (LOG);     # Close the log file.

#                    End logs1.pl
