speedyparse 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/sh
  2. #
  3. # Parse lighttpd access logs for website hits
  4. # Chris Dorman, 2020 - CC-BY-SA-NC 3.0
  5. #
  6. # Include configuartion file
  7. . `pwd`/config
  8. # Date string for html generation
  9. datestring=`date +"%Y%m%d-%H%M"`
  10. # Project information
  11. PROJTITLE="SpeedyParse"
  12. PROJVERSION="1.0"
  13. cd $LOGDIR
  14. if [ -f access.log.2.gz ]; then
  15. echo "Extracting access.log files"
  16. tar -xzf *.gz
  17. fi
  18. # Parse latest access.log and put within log file in HTML format.
  19. if [ -z "$SECONDARYSEARCH" ]; then
  20. catchcount=`grep $DOMAIN access.log | grep "${SEARCHSTRING}" | wc -l`
  21. catchlog=`grep $DOMAIN access.log | grep "${SEARCHSTRING}" | sort`
  22. else
  23. catchcount=`grep $DOMAIN access.log | grep "${SEARCHSTRING}" | grep "${SECONDARYSEARCH}" | wc -l`
  24. catchlog=`grep $DOMAIN access.log | grep "${SEARCHSTRING}" | grep "${SECONDARYSEARCH}" | sort`
  25. fi
  26. catchtotal=$catchcount
  27. echo "<!DOCTYPE html>
  28. <html>
  29. <head>
  30. <title>Lighttpd access logs ~ $date</title>
  31. <style type='text/css' rel='stylesheet'>
  32. html { background-color: #454545; color: #bbbbbb; padding: 10px; }
  33. body { background-color: #313131; padding: 20px; border-radius: 8px; border: solid 1px #222222; margin: 0 auto; }
  34. h1, h2, h3, h4, h5, h6 { color: #ffffff; padding: 4px; width: 100%; text-align: center; margin: auto; }
  35. code { white-space: pre-wrap; padding: 5px; color: #00ff00; text-align: left; }
  36. .footer { width: 100%; text-align: center;
  37. </style>
  38. </head>
  39. <body>
  40. <h3>Access.log information ~ ${datestring}</h3>
  41. <code>
  42. Searching through lighttpd logs with these parameters:
  43. &quot;${SEARCHSTRING}&quot;" > $OUTPUTDIR/$DOMAIN-${datestring}.html
  44. if [ ! -z "$SECONDARYSEARCH" ]; then
  45. echo "&quot;${SECONDARYSEARCH}&quot;" >> $OUTPUTDIR/$DOMAIN-${datestring}.html
  46. fi
  47. echo "
  48. </code>
  49. <b>access.log ~ ${catchcount} hits</b><br />
  50. <code>
  51. ${catchlog}
  52. </code>
  53. <br /><br />
  54. " >> $OUTPUTDIR/$DOMAIN-${datestring}.html
  55. # Parse old .log files and output within HTML
  56. for file in access.log.*
  57. do
  58. if [ -z "$SECONDARYSEARCH" ]; then
  59. addition=`grep $DOMAIN $file | grep "${SEARCHSTRING}" | wc -l`
  60. catchlog=`grep $DOMAIN $file | grep "${SEARCHSTRING}" | sort`
  61. else
  62. addition=`grep $DOMAIN $file | grep "${SEARCHSTRING}" | grep "${SECONDARYSEARCH}" | wc -l`
  63. catchlog=`grep $DOMAIN $file | grep "${SEARCHSTRING}" | grep "${SECONDARYSEARCH}" | sort`
  64. fi
  65. doaddition=$(( $catchcount + $addition ))
  66. export catchcount=$doaddition
  67. echo "<b>$file ~ ${addition} hits</b><br />" >> $OUTPUTDIR/$DOMAIN-${datestring}.html
  68. echo "<code>${catchlog}</code><br /><br />" >> $OUTPUTDIR/$DOMAIN-${datestring}.html
  69. done
  70. echo "<b>${doaddition} hits total on ${DOMAIN} using above search parameters.</b><br /><br />" >> $OUTPUTDIR/$DOMAIN-${datestring}.html
  71. echo "<div class='footer'>Generated by ${PROJTITLE} ${PROJVERSION}</div></body></html>" >> $OUTPUTDIR/$DOMAIN-${datestring}.html