This file is indexed.

/usr/sbin/monthly is in wwwstat 2.0-7.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/perl -w
# ==========================================================================
# Copyright (c) 1996 Regents of the University of California.
#
# This software has been developed by Roy Fielding <fielding@ics.uci.edu> as
# part of the WebSoft project at the University of California, Irvine.
#         <http://www.ics.uci.edu/pub/websoft/wwwstat/>
# See the file LICENSE for licensing and redistribution information.
#
# This program is provided ONLY as an example.  It is not needed to run
# wwwstat and is not supported by the author.
#
sub usage {
    die <<"EndUsage";
USAGE:  monthly

  THIS PROGRAM MUST ONLY BE RUN ONCE PER MONTH, DURING THE FIRST WEEK
  It assumes a lot, like that you use wwwstat and archive your logfiles
  once per month.  You will need to configure it for your server before
  it can be used.

  Reads the logfile (assumed to contain more than one month's worth
  of WWW common logfile entries) and moves the prior month's entries
  into a separate file.  The new file is created on TMPDIR (to avoid
  filling up the disk), compressed using gzip, and then moved to the
  archive directory.  The program also restarts the httpd server.

EndUsage
}
if ($#ARGV >= 0) { &usage; }
# ==========================================================================
# Get defaults

umask(022);

# Compression command and extension

$zcommand    = 'gzip -9';
$zextension  = '.gz';

$wstatcmd    = 'wwwstat';

# Set up the filenames to be used

$ServerRoot = '/usr/local/etc/httpd';

$NewLog   = $ServerRoot . '/logs/access_log';    # Current logfile
$OldLog   = $NewLog . '.old';                    # and temp location

$PidFile  = $ServerRoot . '/logs/httpd.pid';     # Server's PID file
$ErrorLog = $ServerRoot . '/logs/error_log';     # Server's Error Log

$TempLog = "/tmp/templog-$$.txt";      # Temporary file for last month's log

require "/etc/wwwstat/monthly.rc";

print "Got the defaults\n";

# ==========================================================================
# Figure out the archive name

$ArcName = "/dc/ud/www/oldlogs/%M_access_log" . $zextension;

@MoY = ('Jan','Feb','Mar','Apr','May','Jun',
        'Jul','Aug','Sep','Oct','Nov','Dec');

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($mon == 0) { $mon = 11; $year -= 1; }
else           { $mon -= 1; }

$LastMonth = $MoY[$mon];

$ArcName  =~ s/%M/$LastMonth$year/;

$ArcStats = '/dc/ud/www/documentroot/Admin/stats-19' . $year .
            '/' . $LastMonth . '.wwwstats.html';

print "Figured out that last month was $LastMonth $year\n";

# ==========================================================================
# Open logfiles

if (-e $OldLog)             { die "$OldLog already exists, stopped"; }

rename($NewLog, $OldLog)   || die "$!: Failed to rename $NewLog, stopped";

open(OLDLOG, $OldLog)      || die "$!: Failed to open $OldLog, stopped";

open(TEMPLOG, ">$TempLog") || die "$!: Failed to open $TempLog, stopped";

open(NEWLOG, ">$NewLog")   || die "$!: Failed to open $NewLog, stopped";

print "Successfully opened the log files\n";

# ==========================================================================
# Iterate through the old logfile

print "Splitting $NewLog\n";

LINE: while (<OLDLOG>)
{
    #
    # First, parse the common log format into its seven basic components
    #

    ($host, $rfc931, $authuser, $timestamp, $request, $status, $bytes) =
        /^(\S+) (\S+) (\S+) \[([^\]]*)\] \"([^"]*)\" (\S+) (\S+)/;

    # Now, is this garbage or is it memorex?  Note that $bytes can be 0

    if (!($host && $rfc931 && $authuser && $timestamp && $request && $status))
    {
        next LINE;
    }

    # Finally, extract the month and determine where to write this entry

    $month = substr($timestamp, 3, 3);

    if ($month eq $LastMonth) { print TEMPLOG; }
    else                      { print NEWLOG; }
}
close(OLDLOG);
close(TEMPLOG);
close(NEWLOG);

print "Successfully processed the logfiles\n";

# Restart the httpd server

if ($PidFile)
{
    rename($ErrorLog, $ErrorLog . '.old');   # Reset the error log as well
    if (open(PID, $PidFile))
    {
        chop($_ = <PID>);
        kill 1, $_;
        close(PID);
        print "Restarted httpd at $_\n";
    }
}

# Delete the old logfile

print "Deleting $OldLog\n";
system('rm','-f', $OldLog);
if (-e $OldLog) { print STDERR "Warning: Failed to delete $OldLog\n"; }

# Run wwwstat on the temporary log to get last month's stats

print "Creating monthly stats in $ArcStats\n";
system("$wstatcmd $TempLog > $ArcStats");
system("$zcommand $ArcStats");

# Compress the temporary logfile

print "Compressing last month's log\n";

system("$zcommand $TempLog");
if (-e $TempLog) { die "Failed to $zcommand $TempLog\n"; }
$TempLog .= $zextension;

# Move the temporary logfile to its archive location

print "Moving last month's log to $ArcName\n";
system('mv','-f', $TempLog, $ArcName);
if (!(-e $ArcName)) { die "Failed to move $TempLog to $ArcName\n"; }

print "Finished Job\n";

exit(0);