39 lines
1,017 B
Bash
Executable file
39 lines
1,017 B
Bash
Executable file
#!/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)"
|
|
tmpfile="$(mktemp -p "$destdir")"
|
|
trap 'rm -f "$tmpfile"' EXIT
|
|
combine-logs -d "$isodate" \
|
|
/srv/weblog/*/"${vhost}".access.log* | xz -6 > "$tmpfile"
|
|
if [ "$(xzcat "$tmpfile" | cut -c 1)" = "" ]; then
|
|
rm -f "$tmpfile"
|
|
break
|
|
else
|
|
chmod 0640 "$tmpfile"
|
|
mv "$tmpfile" "${destdir}/access.log.${isodate}.xz"
|
|
fi
|
|
done
|
|
done
|