在 2010-01-05二的 16:54 +0100,Angelo Höngens写道: > On 5-1-2010 16:49, Roland Roland wrote: > > Hello, > > > > i'm looking to do the following hope someone could help me if its > > actually feasible.. > > each day at 8 AM, i want access.log to be renamed to > > access.log.DateOfPreviousDay > > that way on any given day access.log would only contains hits of the > > current day.. > > the reason i want this, is that i have SARG set to read everything from > > /var/log/squid/access.log and outputs it in a nice graphical interface.. > > though the problem is that i have hits from every day appended to the > > hits of the previous day hence the request above.. > > hope this all makes sense to you... > > > > thanks in advance:) > > > > And what is your exact question? > > > I have a script to rotate my logs every night as well on my FreeBSD > boxes. I don't know what the problem is you are experiencing, but it > might give you some inspiration: (you have to fix the line breaks yourself): > > -------------------------------------------- > #!/bin/sh > set -e > > yesterday_secs=`perl -e 'print time -43200'` > yesterday_date=`date -r $yesterday_secs +%Y%m%d` > This one is easier: yesterday_date=`date --date="yesterday" +"%Y%m%d"` OR: --date="-3 day"...--date="-5 day" > cd /usr/local/squid/logs/ > > # rename the current log file without interrupting the logging process > > mv /usr/local/squid/logs/access.log > /usr/local/squid/logs/access.log.$yesterday_date > mv /usr/local/squid/logs/store.log > /usr/local/squid/logs/store.log.$yesterday_date > mv /usr/local/squid/logs/cache.log > /usr/local/squid/logs/cache.log.$yesterday_date > > # tell Squid to close the current logs and open new ones > > /usr/local/sbin/squid -k rotate > > # give Squid some time to finish writing swap.state files > /bin/sleep 30 > > mv /usr/local/squid/logs/access.log.$yesterday_date > /usr/local/squid/logs/archive/ > mv /usr/local/squid/logs/store.log.$yesterday_date > /usr/local/squid/logs/archive/ > mv /usr/local/squid/logs/cache.log.$yesterday_date > /usr/local/squid/logs/archive/ > > gzip -9 /usr/local/squid/logs/archive/access.log.$yesterday_date > gzip -9 /usr/local/squid/logs/archive/store.log.$yesterday_date > gzip -9 /usr/local/squid/logs/archive/cache.log.$yesterday_date > > chmod 666 /usr/local/squid/logs/archive/* > -------------------------------------------- >