diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/modules/file.pm | 54 | ||||
| -rwxr-xr-x | scripts/mreplace.sh | 12 | ||||
| -rwxr-xr-x | scripts/replace.sh | 6 | ||||
| -rw-r--r-- | scripts/stats.pl | 92 | ||||
| -rwxr-xr-x | scripts/stats/calc.sh | 49 | ||||
| -rwxr-xr-x | scripts/stats/clean.sh | 49 | ||||
| -rwxr-xr-x | scripts/stats/replace.sh | 11 | ||||
| -rwxr-xr-x | scripts/stats/stats.sh | 61 |
8 files changed, 334 insertions, 0 deletions
diff --git a/scripts/modules/file.pm b/scripts/modules/file.pm new file mode 100644 index 0000000..4326026 --- /dev/null +++ b/scripts/modules/file.pm @@ -0,0 +1,54 @@ +# Xerl Copyright (c) 2005 2006 2007 2008, Paul Buetow (http://www.pblabs.net) +# +# E-Mail: xerl@dev.buetow.org WWW: http://xerl.perl9.org +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of P. B. Labs nor the names of its contributors may +# be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY Paul Buetow ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +sub dopen { + my $shift = shift; + opendir DIR, $shift or die "$shift: $!\n"; + my @dir = readdir(DIR); + closedir DIR; + return @dir; +} + +sub fopen { + my $shift = shift; + open FILE, $shift or die "$shift: $!\n"; + my @file = <FILE>; + close FILE; + return @file; +} + +sub fwrite { + my $shift = shift; + my @file = @_; + open FILE, ">$shift" or die "$shift: $!\n"; + print FILE @file; + close FILE; +} + +1; diff --git a/scripts/mreplace.sh b/scripts/mreplace.sh new file mode 100755 index 0000000..1ef5cc4 --- /dev/null +++ b/scripts/mreplace.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +for j in pm pl xml txt css +do + for i in `find . -name "*.$j"` + do + echo $i + sed "s/$1/$2/g" $i > temp + mv -f temp $i + done +done + diff --git a/scripts/replace.sh b/scripts/replace.sh new file mode 100755 index 0000000..c6f9d4c --- /dev/null +++ b/scripts/replace.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +sed "s/$2/$3/g" $1 > temp +mv -f temp $1 + + diff --git a/scripts/stats.pl b/scripts/stats.pl new file mode 100644 index 0000000..425261f --- /dev/null +++ b/scripts/stats.pl @@ -0,0 +1,92 @@ +#!/usr/bin/perl + +# The yChat Project (2003, 2004) +# The Xerl Project (2005, 2006) +# +# This script generates source code and project statistics + +use strict; + +use scripts::modules::file; + +my %stats; +my $param = shift; + +recursive('.'); + +$stats{"Lines total"} = + $stats{"Lines of source"} + + $stats{"Lines of scripts"} + + $stats{"Lines of text"} + + $stats{"Lines of CSS"} + + $stats{"Lines of XML"}; + +unless ( defined $param ) { + print "$_ = " . $stats{$_} . "\n" for sort keys %stats; + +} +else { + print $stats{$_} . ' ' for sort keys %stats; +} + +print "\n"; + +sub recursive { + my $shift = shift; + return unless -d $shift; + my @dir = dopen($shift); + + foreach (@dir) { + next if /^\.$/o or /^\.{2}$/o; + + if ( -f "$shift/$_" ) { + ++$stats{"Number of files total"}; + filestats("$shift/$_"); + + } + elsif ( -d "$shift/$_" ) { + ++$stats{"Number of dirs total"}; + recursive("$shift/$_"); + } + } +} + +sub filestats { + my $shift = shift; + if ( $shift =~ /\.(cpp|h|tmpl)$/o ) { + ++$stats{"Number of source files"}; + $stats{"Lines of source"} += countlines($shift); + + } + elsif ( $shift =~ /\.css$/o ) { + ++$stats{"Number of CSS files"}; + $stats{"Lines of CSS"} += countlines($shift); + + } + elsif ( $shift =~ /\.(gif|png|jpg)$/o ) { + ++$stats{"Number of gfx files"}; + + } + elsif ( $shift =~ /(\.xml)$/o ) { + ++$stats{"Number of XML files"}; + $stats{"Lines of XML"} += countlines($shift); + + } + elsif ( $shift =~ /(\.pl|\.pm|\.sh|configure.*|Makefile.*)$/o ) { + ++$stats{"Number of script files"}; + $stats{"Lines of scripts"} += countlines($shift); + + } + elsif ( $shift =~ /(\.txt|[A-Z]+)$/o ) { + ++$stats{"Number of text files"}; + $stats{"Lines of text"} += countlines($shift); + + } + elsif ( $shift =~ /\.so$/o ) { + ++$stats{"Number of compiled module files"}; + } +} + +sub countlines { + return scalar fopen shift; +} diff --git a/scripts/stats/calc.sh b/scripts/stats/calc.sh new file mode 100755 index 0000000..dfb7453 --- /dev/null +++ b/scripts/stats/calc.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# By Paul C. Buetow (http://www.buetow.org) + +perl=' + /.*? (.*?) (.*?) /o + && ++$ip{$2}{$1} && ++$p{$1} + && ++$h{$2} && ++$t + for <>; + $l = do { $_ = length $t; $_ < 4 ? 4 : $_ }; + printf " # %$l"."s%4s %$l"."s%4s %24s\n", + "HITS", "%", "UNIQ", "%", "SITE ADDRESS"; + printf "%2.d %$l.d%4.f %$l.d%4.f %24s\n", + ++$i, $h{$_}, 100*$h{$_}/$t, + ($n = keys %{$ip{$_}}), 100*$n/(keys %p),$_ + and $i==15 && last + for sort { $h{$b} <=> $h{$a} } keys %h' + +ls=`ls *.log` +cat << STATS | less +Weekly top 15: + +`echo "$ls" | tail -n 7 | xargs cat | perl -e "$perl"` + +Monthly top ten: + +`echo "$ls" | tail -n 28 | xargs cat | perl -e "$perl"` + +Yearly top ten: + +`echo "$ls" | tail -n 356 | xargs cat | perl -e "$perl"` + +STATS +ftp://ftp.buetow.org download top ten: + +exit 0 +`gawk ' + $9 ~ /^\/data\/ftp\// { ++dl[\$9] } + END { + for (k in dl) + d[k] = sprintf("%3d %s", dl[k], k) + n = asort(d) + rank = 1 + for (i = n; i > 0 && rank < 11; --i) + printf "%2.d%s\n", rank++, d[i] + }' /var/log/proftpdtransfer.log | sed s,/data/ftp/,,` + +This stats are powered by Perl, GNU AWK and Bourne Shell +STATS + diff --git a/scripts/stats/clean.sh b/scripts/stats/clean.sh new file mode 100755 index 0000000..ba0f0e8 --- /dev/null +++ b/scripts/stats/clean.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# 2006 - 2008 The Xerl Project + +for log in *.log +do + re='' + for remove in \ + Charlotte \ + Exabot \ + Mnogo \ + Netcraft \ + Perl \ + Python \ + SurveyBot \ + VoilaBot \ + Yandex \ + Yeti \ + ajSitemap \ + archiver \ + crawler \ + feed \ + findlinks \ + fulltext \ + googlebot \ + grabber \ + jeeves \ + msnbot \ + pear \ + pingdom \ + rss2 \ + sagool \ + sbider \ + slurp \ + spider \ + tagsdir \ + validator \ + walhello \ + ;do + if [ -z "$re" ] + then + re="($remove)" + else + re="$re|($remove)" + fi + done + grep -E -i -v "$re" $log > $log.new + mv -f $log.new $log +done diff --git a/scripts/stats/replace.sh b/scripts/stats/replace.sh new file mode 100755 index 0000000..1624364 --- /dev/null +++ b/scripts/stats/replace.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +from="vs.buetow.org" +to="vs-sim.buetow.org" + +for log in *.log +do + sed "s/$from/$to/" $log > $log.new + mv -f $log.new $log +done + diff --git a/scripts/stats/stats.sh b/scripts/stats/stats.sh new file mode 100755 index 0000000..0f1c070 --- /dev/null +++ b/scripts/stats/stats.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# 2007 (C) Paul C. Buetow (http://paul.buetow.org) + +if [ "$1" != "xerl" ] +then + perl=' + /.*? (.*?) (.*?) /o + && ++$ip{$2}{$1} && ++$p{$1} + && ++$h{$2} && ++$t + for <>; + $l = do { $_ = length $t; $_ < 4 ? 4 : $_ }; + printf " # %$l"."s%4s %$l"."s%4s %24s\n", + "HITS", "%", "UNIQ", "%", "SITE ADDRESS"; + printf "%2.d %$l.d%4.f %$l.d%4.f %24s\n", + ++$i, $h{$_}, 100*$h{$_}/$t, + ($n = keys %{$ip{$_}}), 100*$n/(keys %p),$_ + and $i==20 && last + for sort { $h{$b} <=> $h{$a} } keys %h' +else + perl=' + /.*? (.*?) (.*?) /o + && ++$ip{$2}{$1} && ++$p{$1} + && ++$h{$2} && ++$t + for <>; + $l = do { $_ = length $t; $_ < 4 ? 4 : $_ }; + printf "%02.d %0$l.d %02.f %0$l.d %02.f %24s\n", + ++$i, $h{$_}, 100*$h{$_}/$t, + ($n = keys %{$ip{$_}}), 100*$n/(keys %p), "!!URL(http://$_)!!" + and $i==20 && last + for sort { $h{$b} <=> $h{$a} } keys %h' +fi + +#./clean.sh + +ls=`ls $path*.log` + +cat << STATS +No IP addresses are being logged by Xerl! + + +Yesterdays top list (pos, total hits, total %, unique hits, unique %): + +`echo "$ls" | tail -n 2 | head -n 1 | xargs cat | perl -e "$perl"` + +Last 7 days top list (pos, total hits, total %, unique hits, unique %): + +`echo "$ls" | tail -n 8 | head -n 7 | xargs cat | perl -e "$perl"` + +Last 30 days top list (pos, total hits, total %, unique hits, unique %): + +`echo "$ls" | tail -n 31 | head -n 30 | xargs cat | perl -e "$perl"` + +Last 365 days top list (pos, total hits, total %, unique hits, unique %): + +`echo "$ls" | tail -n 366 | head -n 365 | xargs cat | perl -e "$perl"` + +Overall top list (pos, total hits, total %, unique hits, unique %): + +`echo "$ls" | xargs cat | perl -e "$perl"` +STATS |
