Monday, May 5, 2008

moving log files

I want to clean up some log files but first I want to be sure they are not being written too. Otherwise I'd move the log file and the process that is writing to them (Apache) would get upset and I might interrupt a production system. Note that this is all just paranoia since I know that log files which end in a number have already been rotated.

Here are the log files which are currently open:

lsof | fgrep /var/log/httpd/ | awk {'print $9'} | sort | uniq > open.txt

Here are the log files which I intend to move:

ls -l /var/log/httpd/*.[0-9] | awk {'print $9'} | sort | uniq > move.txt
Now I compare them and get 100% diff, i.e. no intersections:
$ wc -l move.txt open.txt 
  241 move.txt
   84 open.txt
  325 total
$ diff move.txt open.txt | wc -l
327
$ 
The extra two lines come from "1,241c1,84" and "---" which diff added. So I'll move the logs:
mv /var/log/httpd/*.[0-9] /root/oldlogs/

No comments: