]> git.donarmstrong.com Git - infobot.git/commitdiff
log scripts
authortimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Wed, 26 Feb 2014 21:27:10 +0000 (21:27 +0000)
committertimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Wed, 26 Feb 2014 21:27:10 +0000 (21:27 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1933 c11ca15a-4712-0410-83d8-924469b57eb5

scripts/htmlcalidx.sh [new file with mode: 0755]
scripts/processlog.example [new file with mode: 0755]

diff --git a/scripts/htmlcalidx.sh b/scripts/htmlcalidx.sh
new file mode 100755 (executable)
index 0000000..12c75d7
--- /dev/null
@@ -0,0 +1,143 @@
+#!/bin/bash
+
+TODOM=${TODOM:-`date +%d`}
+TOMONTH=${TOMONTH:-`date +%m`}
+YEAR=${YEAR:-`date +%Y`}
+MONTH=${MONTH:-1}
+MONTHABV=([1]=Jan [2]=Feb [3]=Mar [4]=Apr  [5]=May  [6]=Jun \
+          [7]=Jul [8]=Aug [9]=Sep [10]=Oct [11]=Nov [12]=Dec)
+
+echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
+echo '<html>'
+echo '<head>'
+echo "  <title>apt/ibot/infobot/purl logs for $YEAR</title>"
+echo '  <link rel="shortcut icon" href="/favicon.ico">'
+echo '</head>'
+echo '<body>'
+
+today=`date -d "yesterday" +%Y%m%d`
+subdirs=`find \#* -maxdepth 0 -type d 2>/dev/null`
+if [ -n "$subdirs" ] ; then
+  echo '<h1>Channels (l for latest)</h1>'
+  #echo "<table>"
+  echo '<p>'
+  for subdir in $subdirs ; do
+    if [ "$subdir" != "stats" ] ; then
+     subdirhtml=`echo \$subdir | sed -e 's/#/%23/'`;
+     latest=`(cd $subdir ; ls [0-9]* 2>/dev/null| tail -n 1 | sed -e 's/.html.gz//')`
+     if [ "$latest" = "$today" ] ; then
+       #echo "<tr><td><a href=\"$subdirhtml\">$subdir</a></td><td><a href=\"$subdirhtml/$latest.html.gz\">$latest</a></td></tr>"
+       echo "<a href=\"$subdirhtml\">$subdir</a>(<a href=\"$subdirhtml/$latest.html.gz\">l</a>)"
+     fi
+    fi
+  done
+  echo '</p>'
+  #echo "</table>"
+fi
+#if [ -n "$subdirs" ] ; then
+#  echo "<h1>Channels</h1>"
+#  echo "<ul>"
+#  for subdir in $subdirs ; do
+#    if [ "$subdir" != "stats" ] ; then
+#     latest=`(cd $subdir ; ls [0-9]* | tail -n 1 | sed -e 's/.html.gz//')`
+#     echo "<li><a href=\"$subdir\">$subdir</a> <a href=\"$subdir/$latest.html.gz\">$latest</a>"
+#    fi
+#  done
+#  echo "</ul>"
+#fi
+
+echo "<h1>$YEAR</h1>"
+echo '<table>'
+echo '  <tbody>'
+echo '    <tr>'
+
+while [ $MONTH -le $TOMONTH ]; do
+
+  STARTDAY=`date -d "1 ${MONTHABV[$MONTH]} $YEAR" +%w`
+  case $MONTH in
+    2)
+      ENDDOM=28
+      ;;
+    9|4|6|11)
+      ENDDOM=30
+      ;;
+    *)
+      ENDDOM=31
+      ;;
+  esac
+
+  echo '      <td valign=top>'
+
+  echo '        <table border=1>'
+  echo '          <tbody>'
+  echo "            <tr><td align=center colspan=7>${MONTHABV[$MONTH]}</td></tr>"
+  echo '            <tr><td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td></tr>'
+
+  DOM=${DOM:-1}
+  DAY=0
+  INCDOM=no
+  SHOWDOM=no
+  until [ $DAY -eq 0 -a "$INCDOM" = "done" ]; do
+    if [ $DAY -eq 0 ]; then
+      echo -n "            <tr>"
+    fi
+
+    if [ "$INCDOM" = "no" -a $DAY -eq $STARTDAY ]; then
+      INCDOM=yes
+      SHOWDOM=yes
+    fi
+
+    echo -n "<td>"
+    if [ "$SHOWDOM" = "yes" ]; then
+        FILE=`date -d "$DOM ${MONTHABV[$MONTH]} $YEAR" +%Y%m%d`.html.gz
+        if [ -f "$FILE" ]; then
+            echo -n "<a href=\"$FILE\">"$DOM"</a>"
+          else
+            echo $DOM
+        fi
+      else
+        echo -n "&nbsp;"
+    fi
+    echo -n "</td>"
+
+    if [ "$INCDOM" = "yes" ]; then
+        if [ $DOM -eq $ENDDOM ]; then
+            INCDOM="done"
+            SHOWDOM=no
+          else
+            DOM=$(($DOM + 1))
+            if [ $MONTH -eq $TOMONTH -a $DOM -gt $TODOM ]; then
+              SHOWDOM=no
+            fi
+        fi
+    fi
+
+    DAY=$(($DAY + 1))
+    if [ $DAY -eq 7 ]; then
+      echo "</tr>"
+      DAY=0
+    fi
+  done
+  DOM=1
+
+  echo '          </tbody>'
+  echo '        </table>'
+
+  echo '      </td>'
+
+  if [ $MONTH -lt $TOMONTH ]; then
+    if [ $(($MONTH % 4)) -eq 0 ]; then
+      echo "    </tr>"
+      echo "    <tr>"
+    fi
+  fi
+
+  MONTH=$(($MONTH + 1))
+done
+
+echo '    </tr>'
+echo '  </tbody>'
+echo '</table>'
+
+#echo '</body>'
+#echo '</html>'
diff --git a/scripts/processlog.example b/scripts/processlog.example
new file mode 100755 (executable)
index 0000000..fadee64
--- /dev/null
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+# copy or link this to processlog to make it run when logs are rotated
+
+if [ -z "$1" ] ; then
+ echo "Syntax: $0 <file>"
+ exit -1
+elif [ ! -r $file ] ; then
+ echo $file does not exist
+ exit -1
+fi
+
+file="`readlink -fm "$1"`"
+irclog2html=`readlink -fm scripts/irclog2html.pl`
+htmlcalidx=`readlink -fm scripts/htmlcalidx.sh`
+# pull date out of path
+date=`echo "${file}"|sed -e 's~.*\([0-9]\{4\}\)/\([0-9]\{4\}\)$~\1\2~'`
+web=$HOME/web
+
+# delete old web pages if present (to allow re-running)
+rm -f $web/$date.html $web/*/$date.html $web/$date.html.gz $web/*/$date.html.gz
+# create new ones
+(cd $web;${irclog2html} ${date} < $file)
+# set the date to the log date
+touch -r $file $web/$date.html $web/*/$date.html
+# compress them
+gzip -f -9 $web/$date.html $web/*/$date.html
+
+#don't run stats if not yesterdays log
+if [ "$date" != "`date -u -d '1 day ago' +'%Y%m%d'`" ] ; then
+ NOSTATS=1
+ NOIDX=1
+fi
+
+# only do stats if NOSTATS not set
+if [ -z "$NOSTATS" ] ; then
+ cd $web/stats
+ [ -r .log ] && rm .log
+ ln -s $file .log
+ nice -n 20 pisg
+ rm .log *gz
+ gzip -9 *html
+fi
+
+if [ -z "$NOSTATS" ] ; then
+ for a in `find $web -type d|sort` ; do
+  (cd $a ; ${htmlcalidx} > HEADER.html)
+ done
+ rm $web/stats/HEADER.html
+fi
+
+if [ -z "$NOCOMPRESS" ] ; then
+ bzip2 -9 $file
+fi