Log Import Script for cron


#1

Hello guys,

here is a little “beginner” script for a log import over cron.

Please be aware if you use this for production systems (in testing phase).


#!/bin/bash
### Version: 1.0
### Author: Christian Wollinger
############### Description ###############
### - Piwik Log Import

### 1. Step
cp /<path>/logfile_test /<path>/logfile_test.import

if [ -r "/<path>/LOG_Anzahl.txt" ]; then
				
				#1. Import after existing LOG_Anzahl.txt (created on first run)
                LOG_Anzahl=`cat /<path>/LOG_Anzahl.txt`
                /var/www/piwik/misc/log-analytics/import_logs.py --url=http://example.com/piwik/ --idsite=1 --recorders=4 --enable-reverse-dns --enable-http-errors --enable-http-redirects --enable-static --enable-bot --exclude-path=/piwik/* --skip=$LOG_Anzahl /<path>/logfile_test.import
                LOG_Anzahl=`wc /<path>/logfile_test.import | awk '{print $1}'`
                echo $LOG_Anzahl > /<path>/LOG_Anzahl.txt
                else
				
				#First run
                LOG_Anzahl=`wc /<path>/logfile_test.import | awk '{print $1}'`
                echo $LOG_Anzahl > /<path>/LOG_Anzahl.txt
                /var/www/piwik/misc/log-analytics/import_logs.py --url=http://example.com/piwik/ --idsite=1 --recorders=4 --enable-reverse-dns --enable-http-errors --enable-http-redirects --enable-static --enable-bot --exclude-path=/piwik/* /<path>/logfile_test.import
fi


(Matthieu Aubry) #2

Hi there,

once you are happy with your script, maybe it could be used to improve the README Of the log analytics script? if so, please feel free to issue a pull request: https://github.com/piwik/piwik/tree/master/misc/log-analytics#piwik-server-log-analytics-import-your-server-logs-in-piwik