Advertisement
flipje

generate-webalizer-stats-per-site

Jul 31st, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.64 KB | None | 0 0
  1. #!/bin/bash
  2. WEBSITE="${1}"
  3.  
  4. [ "${#}" = 1 ] || { echo "Usage ${0} vhost (dir in /logging)"; exit 1; }
  5.  
  6. echo -e "\
  7. LogFile /logging/${WEBSITE}/access.log.1
  8. LogType clf\n
  9. OutputDir /var/www/stats/${WEBSITE}\n
  10. HistoryName ${WEBSITE}.hist\n
  11. ReportTitle Usage statistics for
  12. HostName ${WEBSITE}
  13. HTMLExtension  html\n
  14. PageType    htm*
  15. PageType    cgi
  16. PageType    php3
  17. PageType    php\n
  18. UseHTTPS        no\n
  19. Quiet       no
  20. ReallyQuiet no
  21. CountryGraph    yes\n
  22. DailyGraph  yes
  23. DailyStats  yes
  24. HourlyGraph yes
  25. HourlyStats yes
  26. GraphLegend yes
  27. IgnoreSite  localhost
  28. IgnoreReferrer  localhost\n
  29. SearchEngine    yahoo.com   p=
  30. SearchEngine    altavista.com   q=
  31. SearchEngine    google.com  q=
  32. SearchEngine    eureka.com  q=
  33. SearchEngine    lycos.com   query=
  34. SearchEngine    hotbot.com  MT=
  35. SearchEngine    msn.com     MT=
  36. SearchEngine    infoseek.com    qt=
  37. SearchEngine    webcrawler  searchText=
  38. SearchEngine    excite      search=
  39. SearchEngine    netscape.com    search=
  40. SearchEngine    mamma.com   query=
  41. SearchEngine    alltheweb.com   query=
  42. SearchEngine    northernlight.com  qr=
  43. SearchEngine    sensis.com.au   find=
  44. SearchEngine    google.nl   q=
  45. SearchEngine    google.fr   q=
  46. SearchEngine    google.ch   q=
  47. SearchEngine    google.ca   q=
  48. SearchEngine    google.be   q=\n
  49. " > /etc/webalizer/${WEBSITE}-webalizer.conf
  50.  
  51. echo -e "\
  52. #!/bin/sh
  53. WEBALIZER=/usr/bin/webalizer
  54. WEBALIZER_CONFDIR=/etc/webalizer
  55.  
  56. [ -x \${WEBALIZER} ] || exit 0;
  57. [ -d \${WEBALIZER_CONFDIR} ] || exit 0;
  58.  
  59. for i in \${WEBALIZER_CONFDIR}/${WEBSITE}-webalizer.conf
  60. do
  61.  # run agains a rotated or normal logfile
  62.  LOGFILE=\`awk '\$1 ~ /^LogFile$/ {print \$2}' \$i\`;
  63.  
  64.  # empty ?
  65.  [ -s \"\${LOGFILE}\" ] || continue;
  66.  # readable ?
  67.  [ -r \"\${LOGFILE}\" ] || continue;
  68.  
  69.  # there was a output ?
  70.  OUTDIR=\`awk '\$1 ~ /^OutputDir$/ {print \$2}' \$i\`;
  71.  #  exists something ?
  72.  [ \"\${OUTDIR}\" != \"\" ] || continue;
  73.  # its a directory ?
  74.  [ -d \${OUTDIR} ] || continue;
  75.  # its writable ?
  76.  [ -w \${OUTDIR} ] || continue;
  77.  
  78.  # Run Really quietly, exit with status code if !0
  79.  \${WEBALIZER} -c \${i} -Q || continue;
  80.  RET=\$?;
  81.  
  82.  # Non rotated log file
  83.  NLOGFILE=\`awk '\$1 ~ /^LogFile$/ {gsub(/\.[0-9]+(\.gz)?/,\"\"); print \$2}' \$i\`;
  84.  
  85.  # check current log, if last log is a rotated logfile
  86.  if [ \"\${LOGFILE}\" != \"\${NLOGFILE}\" ]; then
  87.    # empty ?
  88.    [ -s \"\${NLOGFILE}\" ] || continue;
  89.    # readable ?
  90.    [ -r \"\${NLOGFILE}\" ] || continue;
  91.  
  92.    \${WEBALIZER} -c \${i} -Q \${NLOGFILE};
  93.    RET=\$?;
  94.  fi;
  95. done;
  96.  
  97. # exit with webalizer's exit code
  98. exit \$RET;
  99. " > /etc/webalizer/${WEBSITE}-webalizer-cron.sh
  100.  
  101.  
  102. echo "Config is generated and stored in /etc/webalizer/, please move the ${WEBSITE}-webalizer-cron.sh file to /etc/cron.hourly"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement