#!@PATH_PROG_PERL@ -s # cgiwrap_anal.pl - log analysis routine for cgiwrap logs with html output # should be run regularly (usually with log rotation) # usage: cgiwrap_anal [-t] [logfile] # -t check and display the type of each script # logfile to be analysed if not the default # # written by: Lawrie.brown@adfa.oz.au - Dec 95 # configurable parameters $log_file=""; # location of default cgiwrap logfile $conf_cgidir="WWW/cgi-bin"; # location of users cgi-bin under home $title="cgiwrap log analysis"; # title used on html document created # need ctime package for &ctime require "ctime.pl"; # check for commandline args $log_file = $ARGV[0] if ($#ARGV >= 0); # grab named logfile # do some sanity checks die "cgiwrap_anal: Unable to read logfile: $log_file\n" unless -T "$log_file"; # get date for today $date = &ctime(time); # get current time # now read and summarise contents of the logfile open(IN, "<$log_file"); while () { @in = split(/\t/,$_); # split entry into tab separated fields $name = "~$in[0]/$conf_cgidir/$in[1]"; # construct script name $cnt{$name}++; # increment calls on this script } close(IN); # now construct html reply showing the log summary print "\n $title \n"; print "\n

$title

\n"; print "

Analysis of $log_file

\n

on $date

\n"; print "\n"; print ""; print "" if ($t); # extra col if want script types print "\n"; # now summarise calls on the scripts foreach $name ( sort keys (%cnt) ) { $total += $cnt{$name}; # increment total count print ""; # display row for script &CheckType($name) if ($t); # check and display script type print "\n"; } # finish up html output print ""; # display row of totals print "" if ($t); # extra col if want script types print "\n"; print "
Script# CallsType
$name$cnt{$name}
TOTAL$total
\n"; print "
\n\n"; exit(0); ############################################################################# # CheckType($name) - check and display script type sub CheckType { local($name) = @_[0]; # script name # expand ~user into full home directory (hack from perl FAQ Q2.31) $name =~ s#^~(\w+)(/.*)?$#(getpwnam($1))[7].$2#e; # expand ~user print ""; if (-r "$name") { # can access script if (-x "$name") { print "executable "; } else { print "non-executable "; } if (-B "$name") { print "binary ";} # binary file else { # text file or script open(SC, "<$name"); # check first line for type $shell = ; if ($shell =~ "^#!") { # is a script $shell =~ s:^#! *\S+/(\S+).*$:\1:; # extract shell name print "$shell script "; # and display it } else { print "text file "; } close(SC); } } else { print "unreadable file"; # no access to script } print ""; }