. 51
( 69 .)


you store your Web log files. If you store your Web logs in

ou can analyze your Web traffic using a tool called
/sw/apache/logs, you must change the line that starts with
Analog. Analog is a free, open source program that
LOGFILE to read LOGFILE /sw/apache/logs/access_log. If
you can use to analyze Web traffic based on records
you do not have the correct log file location, Analog cannot
stored in your log files. Analog can produce as many as 32
analyze your Web traffic.
different reports. For example, it can provide you with
charts that highlight heavy traffic times ” for instance,
Analog analyzes Web traffic by individual file requests, as
times of the day or days of the week. It can also show you
this is the manner in which your system records Web traffic
which of your files visitors access most frequently, which
in your log files. Traffic can be reported hourly, daily,
files are not found, or where visitors are coming from when
weekly, or monthly by turning report options on and off.
they follow links to your Web site.
For example, to turn monthly reports off, you can add
MONTHLY OFF to your configuration file. To turn weekly
Analog has a configuration file, called analog.cfg. Fink
reports on, you can add WEEKLY ON. To produce one of
installs this file into the /sw/etc/analog directory. Like most
the many types of reports available from Analog, you can
configuration files, analog.cfg is full of helpful comments,
scan a list of the available reports and insert commands
and has a number of configuration options. The most
such as REFERRER ON in your configuration file.
important of these options is the line that identifies where


– Fink tells you whether you ‹ Type OUTPUT HTML and
have installed analog. press Return.
„ Type fink list | followed by „ Start Pico with sudo to edit
– A lowercase letter i in the › Type OUTFILE /sw/apache/
a space. /sw/etc/analog/analog.cfg.
leftmost column indicates htdocs/analog0.html and press
¤ Type grep analog and ¤ Change the LOGFILE line
that Fink is installed. Return.
press Return. to include the pathname of
your access_log, and press

Until you start to use the reports that Analog produces, you may not know which
reports are the most useful to you in analyzing your log files. In addition, your
requirements may change over time. The following table describes some of the
reports available to you. To include any of these reports in your Analog output,
insert the keyword, then the word ON, into your analog.cfg file.

MONTHLY One line for each month
WEEKLY One line for each week
DAILYREP One line for each day
HOURLYREP One line for each hour of the day
GENERAL A general summary
REQUEST Files that are requested
FAILURE Files that are not found
REFERRER Where visitors come from using links
FAILREF Sites from which visitors follow broken links
SEARCHWORD Phrases and words visitors use to find your site
STATUS Count of each type of success and failure

– Pico saves your changes to
ˇ Type HOSTNAME ‹ Type /sw/apache/htdocs/
the analog.conf file. analog0.html and press
"Dragonfly Ditch".
„ Type /sw/bin/analog and Return.
Á Save your text, and exit press Return.
– Your Analog report
¤ Type open followed by a displays in a browser


greater than another, or looking for a number in a string,

ou can use Perl to write a simple script that does not
you can ask if a line of text contains an e-mail address or a
require compiling. Perl is an interpreted language.
date/time stamp by describing these items as patterns.
However, Perl looks like a compiled language in a
number of ways. For example, each statement in Perl ends
Although the use of regular expressions can make Perl code
in a semicolon, and a $ symbol precedes variable names,
difficult to interpret at first, when you become more
even when you first declare them and assign them a value.
familiar with each of the symbols, you can begin to
More importantly, Perl allows you to build subroutines, pass
appreciate the succinct form of the language.
variables, and return values like most compiled languages.
Perl also has sophisticated array handling. The elements of a Perl pattern are referred to as
metacharacters. For example, \s represents a single
However, the feature that most distinguishes Perl from
whitespace character “ a blank or a tab ” and \S
other languages is the versatile use of regular expressions. If
represents any non-whitespace character. You can also
your only experience with regular expressions comes from
amend these patterns to match some or none or a string of
working in one of the Unix shells, you may be amazed at
any size. Where \d represents a digit, \d+ represents any
the versatility of the Perl language. For example, you can
number of digits and \d* represents any number of digits,
use regular expressions in Perl to do fuzzy matching. With
but will also match no digits at all.
fuzzy matching, instead of asking whether one number is


„ Type pico followed by a ¤ Type sam.pl and press ‹ Type print followed by a › Type "Hello, World -- ";
space. Return. space. and press Return.
– A blank Pico screen


The "\n" shown in the screens below indicates a
As with most Unix scripting languages and
newline character. If this character were omitted
configuration files, you create a comment in Perl
from our print statement, the script would print the
by placing a # symbol at the beginning of the
output without moving to the new line, and the next
line. You can place a comment on a line by itself
system prompt would be on the same line. You
or append it to the end of a line of code. Either
usually include newline characters in the print
of these forms is correct:
statements along with text that you want to print.
Example: For example, you can type the line print "Hello,
# say hello World\n"; in a Perl script to print the message and
move to the next line.
print "Hello, World “ "; # say hello

When you create a complex script, you should
include some comments that explain what your
script is doing, but avoid superfluous comments
that may annoy someone who reads your code.
In Perl, comments are often used to explain
complex regular expressions.

ˇ Type print followed by a Á Type "I am $0"; and press ‡ Type print followed by a · Save your file, and exit
space. Return. space. Pico.
– Pico saves your new Perl
° Type "\n"; and press
Return. script.


shebang line, and the syntax for this line is #! followed by

ou can run a Perl script by using it as an argument to
the name of the interpreter. For a Perl script, you can type
the Perl interpreter, or by making it executable. After
you create a Perl script, you can instruct Perl to
interpret and execute the script, for example, by typing perl
If you make your Perl script executable without the shebang
myscript.pl. This is the simplest way to run a script, but not
line, the system cannot determine what tool to use to run
the most convenient. Most users prefer to run scripts as
the script, and it attempts to run the commands using your
though they are new commands, and without having to
shell. This action generates a number of errors, as tcsh does
know anything about the language in which they are
not include a print command. If you mistype your
written. Thus, they may not want to type perl before the
shebang line, your system cannot find the interpreter and
name of the script.
issues an error such as "not found: myscript.pl".
For the convenience of users, and to avoid errors that may
You can force yourself to use rules that are more restrictive
generate if they type the name of the script on a line by
in your Perl coding by adding use strict; to the top of
itself, you can insert a line at the top of the script that
your scripts. While adding this to your scripts may generate
identifies your file to the shell as a Perl script, and you can
warning messages, these messages may help you avoid
make the script executable. You refer to this line as the
many potential errors in your code.


„ Type perl followed by a ¤ Type sam.pl and press ‹ Type chmod a+x followed ˇ Type ./sam.pl and press
space. Return. by a space. Return.
– Perl runs your script. – The shell cannot run your
› Type sam.pl and press
Return. print command.
Á Type pico sam.pl and
press Return.

The shebang line tells the shell which language you
You can use the command line option -w on the
used to write the script and, consequently, what
shebang line ” by typing #!/usr/bin/perl -w ”
tool the shell can use to run the commands. For the
to instruct Perl to issue warnings regarding your
script to run, the shebang line must contain the full
syntax. For example, if you define a variable,
path to the Perl interpreter. This is the case whether
such as $counter, and then never use it, Perl
or not the Perl binary is on your search path. Also,
warns you that this variable appears only once in
this line must be the first line in the script and must
your code. By doing this, Perl is telling you that
start with #!.
you have made a mistake or, at least, strayed
from your original intent in writing the script.
Perl warnings are very useful when you are first


. 51
( 69 .)