Commit 4756ee01 authored by Chris Croome's avatar Chris Croome

Kate's Apache data usage script added

parent 172138b2
Pipeline #7444 passed with stage
in 21 seconds
#!/bin/bash
data_tmp=/tmp/apache
logfiles=/var/log/apache2/
rcpts="$1"
host=$(hostname -f)
# Identify users.
## Do this by looking at apache configuration and using that to build a list of users
## Why this way ... well it's apache we need to be thinking about ? so it seems as good an
## any other way to do it
users=$(grep AssignUserID /etc/apache2/sites-available/*conf | awk '{print $3}' | sort | uniq )
report="User RX_GiBYTES TX_GiBYTES TOTAL_GiBYTES\n-----------------------\n"
for user in $users
do
echo $user
rm -r $data_tmp
mkdir $data_tmp
find $logfiles -name $user"_access.log*" -exec cp {} $data_tmp \;
gunzip $data_tmp/*gz
RX=$(cat $data_tmp/*log* | awk '{ SUM += $1} END { print SUM }')
TX=$(cat $data_tmp/*log* | awk '{ SUM += $2} END { print SUM }')
if [[ z$RX = "z" ]]
then
RX=0
fi
if [[ z$TX = "z" ]]
then
TX=0
fi
TOTAL=$(($RX+$TX))
RX=$(echo $RX/1024/1024/1024 | bc -l )
TX=$(echo $TX/1024/1024/1024 | bc -l )
if [[ z$RX = "z" ]]
then
RX=0
fi
if [[ z$TX = "z" ]]
then
TX=0
fi
TOTAL=$(echo $TOTAL/1024/1024/1024 | bc -l )
report="$report $user $RX $TX $TOTAL \n"
done
echo -e $report
for rcpt in $rcpts
do
echo -e $report | mutt -s "Apache Data Usage last 28 days by user on $host" -- $rcpt
done
# Send report
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment