Do, or do not. There is no ‘try’

Sarg three scripts for daily, weekly and monthly statistics.

Hi,

here are three scripts for daily, weekly and monthly statistics. After the monthly statistics the access.log will be rotated.
This is based on Jeremy Lahners first script on your web page, many thanks to him.

Daily (Jeremy´s script):
————————————-

#!/bin/bash

#Get current date
TODAY=$(date +%d/%m/%Y)

#Get one week ago today
YESTERDAY=$(date –date “1 day ago” +%d/%m/%Y)

/usr/local/bin/sqmgrlog -l /usr/local/squid/logs/access.log -o /usr/local/apache/htdocs/reports/daily -z -d $YESTERDAY-$TODAY

exit 0

Weekly
————————————-

#!/bin/bash

#Get current date
TODAY=$(date +%d/%m/%Y)

#Get one week ago today
YESTERDAY=$(date –date “1 week ago” +%d/%m/%Y)

/usr/local/bin/sqmgrlog -l /usr/local/squid/logs/access.log -o /usr/local/apache/htdocs/reports/weekly -z -d $YESTERDAY-$TODAY

exit 0

Monthly

#!/bin/bash

#Get current date
TODAY=$(date +%d/%m/%Y)

#Get one week ago today
YESTERDAY=$(date –date “1 month ago” +%d/%m/%Y)

/usr/local/bin/sqmgrlog -l /usr/local/squid/logs/access.log -o /usr/local/apache/htdocs/reports/monthly -z -d $YESTERDAY-$TODAY

/usr/local/squid/bin/squid -k rotate

exit 0

And the same for the admin who want the report as an email (example for daily)

#!/bin/bash

#Get current date
TODAY=$(date +%d/%m/%Y)

#Get one week ago today
YESTERDAY=$(date –date “1 day ago” +%d/%m/%Y)

/usr/local/bin/sqmgrlog -l /usr/local/squid/logs/access.log -e user@site.com -z -d $YESTERDAY-$TODAY

exit 0
~

Cheers
Lars

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.