#!/usr/bin/perl
# run getstats to create reports from httpsd log files
#  from the secure server running on www1.columbia.edu

die "usage: run-gs-www1.pl <date>\n\nfor example: run-gs-www1.pl 19980221\n"
				unless $#ARGV == 0;

$date=$ARGV[0];
$| = 1;					# unbuffered output
$GETSTATS='/opt/ACISweb/bin/getstats/getstats';
$GETSTATS='/usr/local/bin/getstats' unless -x $GETSTATS;
die "can't find getstats\n" unless -x $GETSTATS;

if    (-x '/opt/local/bin/gzip')     {$GZIP='/opt/local/bin/gzip';}
elsif (-x '/usr/local/bin/gzip')     {$GZIP='/usr/local/bin/gzip';}
else                                 {$GZIP='';}

$rpt='/wwws/data/acis/rad/web-usage/www1';
$log='/www/data/httpd/log';
$msg="/tmp/getstats-www1-$date";

print STDERR "getstats will create www1 reports for $date\n";

open (CMD, "|$GETSTATS") || die "can't execute $GETSTATS\n";

print CMD "
set date $date
set msgfile $msg
set defaulthost www1.columbia.edu
set domroot www1.columbia.edu   $rpt/dom
set xtroot  www1.columbia.edu   $log/xt/www1

# how many levels to keep in memory
set dtrlevels 6
set domlevels 2
set countbytes yes
set counthosts yes
read std $log/sec/howsit/httpsd.access.$date.gz

#####
# print reports for the secure server
set servername \"https://www1.columbia.edu/\"
set icon \"https://www1.columbia.edu/icons/getstats.gif\"

set ignorepublic yes
set sortkey nreq
set ignoreimages no
write dirtree 6 $rpt/$date.dtrreq6.html
write dirtree 5 $rpt/$date.dtrreq5.html
write dirtree 4 $rpt/$date.dtrreq4.html
write dirtree 3 $rpt/$date.dtrreq3.html
write dirtree 2 $rpt/$date.dtrreq2.html
write dirtree 1 $rpt/$date.dtrreq1.html

set ignoreimages yes
write dirtree 6 $rpt/$date.htrreq6.html
write dirtree 5 $rpt/$date.htrreq5.html
write dirtree 4 $rpt/$date.htrreq4.html
write dirtree 3 $rpt/$date.htrreq3.html
write dirtree 2 $rpt/$date.htrreq2.html
write dirtree 1 $rpt/$date.htrreq1.html

write domain  1 $rpt/dom/$date.domreq1.html
write redir   6 $rpt/$date.redir.html
write error   6 $rpt/$date.error.list
";
close (CMD);

system("chgrp www $rpt/$date*");
system("chmod o-r $rpt/$date*");
unlink("$msg.gz") if -r "$msg.gz";	# remove old compressed file
if ($GZIP) {system("$GZIP $msg");}
else       {print "can't find gzip, $msg not compressed\n";}

exit;
