Jun 262012
 

Squid logs can be rotated using newsyslog, logrotate, or squid -k rotate. If using squid, they will not be compressed and those logs can get quite big. Wrote a small script that renames the just closed log using yesterday’s date and gzips it. This way there will be a month worth of logs around. Kinda, doesn’t care for how many days a month has.

Runs every night at midnight and it was written for OpenBSD. This is relevant for line 18, which obtains yesterday’s date by converting current date to seconds since epoch, subtracting 24 hours and converting back. On FreeBSD there’s date -v-1d +%d for that, using GNU (Linux) date, it would be date --date="yesterday" +%d.

Because squid -k rotate takes a while to complete the rotation, but exits right away, the script just sleeps for 10 minutes in order to allow the process to complete. The proper way would probably be to periodically check if it’s done, but it’s good enough for me.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)