Purging Log Files a.k.a A logadm Letdown
This morning I set out to do something fairly simple. I’ve got a directory full of JumpStart log files (generated as a client is JumpStarted) and I want to purge everything older than six months.
Should be a simple one liner cron job right? You’re right, it is. But I had to discover what it wasn’t before I could reach that conclusion.
Here’s my directory structure:
/export/home/loguser/clienthostname-timestamp/ and inside each clienthostname-timestamp directory is a bunch of log files, some with unique names.
I wanted to use logadm to rotate the old logs right out of existance. After a lot of discovering all sorts of things logadm could do for me, it turns out that just deleting a directory full of files isn’t one of them. Delete the contents of a file? No problem. Delete the file itself? Not a chance. Bummer.
In the end, find is going to do exactly what I want:
find /export/home/loguser -type d -mtime +180 -exec rm -rf {} \;
That’s all good and simple and I’m happy with that solution. But if I knew I could just do that, why did I burn so much time trying to get logadm to play nice?
I wanted to use what seemed to be the right tool for the job. From the logadm man page:
logadm - manage endlessly growing log files
It sounds right, and more importantly, whoever comes after me looking for why log files seem to be disappearing is probably going to start their search there. Log files… think logadm. Unfortunately, it’s not going to be quite that simple for them and I’m keenly aware that “them” could very well be me.
