web_logs: Refactor and store daily logs
This commit is contained in:
parent
099304e7e6
commit
61eade7662
2 changed files with 77 additions and 24 deletions
37
roles/web_logs/files/parse-access-logs.sh
Executable file
37
roles/web_logs/files/parse-access-logs.sh
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
umask 027
|
||||
|
||||
get_vhosts() {
|
||||
{
|
||||
for hostdir in /srv/weblog/* ; do
|
||||
[ -d "$hostdir" ] || continue
|
||||
for log in "${hostdir}/"*.access.log ; do
|
||||
[ -f "$log" ] || continue
|
||||
basename "$log" ".access.log"
|
||||
done
|
||||
done
|
||||
} | sort | uniq
|
||||
}
|
||||
|
||||
print_date() {
|
||||
date -r "$(($(date +%s) - $1 * 86400))" "+%Y-%m-%d"
|
||||
}
|
||||
|
||||
get_vhosts | while read -r vhost ; do
|
||||
destdir="/srv/weblog/parsed/${vhost}"
|
||||
[ -d "$destdir" ] || mkdir "$destdir"
|
||||
for i in $(seq 0 7); do
|
||||
isodate="$(print_date $i)"
|
||||
outfile="${destdir}/access.log.${isodate}"
|
||||
combine-logs -d "$isodate" \
|
||||
/srv/weblog/*/"${vhost}".access.log* > "${outfile}.tmp"
|
||||
if [ -s "${outfile}.tmp" ]; then
|
||||
mv "${outfile}.tmp" "$outfile"
|
||||
else
|
||||
rm -f "${outfile}.tmp"
|
||||
break
|
||||
fi
|
||||
done
|
||||
done
|
Loading…
Add table
Add a link
Reference in a new issue