#!/bin/sh

cleanup() {
  bzip2 "$logfn"                # bzip logfile
}

logdir=/srv/http/tmp/data       # log dir
logfn="$logdir"/apclinev.log    # log filename
bzfn="$logfn".bz2               # compressed log filename

test -w "$bzfn" && bzip2 -d "$bzfn"   # unzip if bz2 exists

## set trap to bzip2 logfile and handle fd restore and close
trap cleanup TERM INT EXIT

## write stdin to logfile
cat - >>"$logfn"

