View Single Post
Old 02-19-2016, 04:34 PM   #1197
mariosipad
Guru
mariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watch
 
Posts: 726
Karma: 10738
Join Date: Nov 2012
Device: iPad & iPhone with Marvin 2 + 3 & Kobo Glo HD
Quote:
You haven't got the user I have and if it keeps going, neither will I
Yeah, but if you delete all the problems, there are no challenges left.

Quote:
I haven't got any further as I'm on baby sitting duties with my
grandson again....
Well family should come first! I'm "dogsitting" this week, lots of excercise for me.

Here is my preliminary solution. No error checking etc, it just works (for me).
Code:
#!/bin/bash
# email log entries of COPS users for previous 24 hours

DATE=$(date +%d-%b-%Y)
#LOGFILE=/var/log/apache2/other_vhosts_access.log
LOGFILE=/var/log/apache2/access.log

DATABASE[0]='/path/one/to/metadata.db'
DATABASE[1]='/path/two/to/metadata.db'
DATABASE[2]="/path/three/to/metadata.db"
DATABASE[3]='/path/four/to/metadata.db'
DATABASE[4]='/path/five/to/metadata.db' 

grep -e "epub" -e "mobi"  $LOGFILE | grep -e "200" > book-log.txt

LOGFILE=book-log.txt
TMPFILE=tmp.$LOGFILE

rm -f $TMPFILE 2> /dev/null

cat $LOGFILE 2> /dev/null | while read LINE
do
  IP=$(echo $LINE | cut -f 1 -d' ')
  USER=$(echo $LINE | cut -d ' ' -f 3)
  TIME=$(echo $LINE | cut -f2 -d'[' | cut -f1 -d' ')

  QSTR=$(echo $LINE | cut -f7 -d' ' | cut -f2 -d'?')
  DATA=$(echo $QSTR | cut -f1 -d'&' | cut -f2 -d'=')
  TYPE=$(echo $QSTR | cut -f2 -d'&' | cut -f2 -d'=')
  ID=$(echo $QSTR | cut -f3 -d'&' | cut -f2 -d'=')
  DB=$(echo $QSTR | cut -f4 -d'&' | cut -f2 -d'=')

  DBASE=${DATABASE["$DB"]}

  SQL="select title, author_sort from books where id="$ID" ;" 

  TITLE=$(sqlite3 $DBASE "$SQL")

#  echo "$TIME $USER $IP $BOOK $DATA $TYPE $ID $DB $TITLE" >> $TMPFILE
  echo "$TIME $USER $IP $TITLE" >> $TMPFILE

done

if [[ ! -s $TMPFILE ]]
then
  echo "There is no data to report." >> $TMPFILE
fi

# cat $TMPFILE | mail -s "Today's COPS users $DATE" -r "yourfrommailaddress@mail.com>" yourmail@mail.com

#rm -f $TMPFILE 2> /dev/null

# END
helped a lot!
mariosipad is offline   Reply With Quote