Bash Log Rotation Script for OSX

Jordan Gardner
1 min readDec 11, 2015

At MyEducator we’ve increased the redundancy of our backups (student files, system files, database backups, etc.) by purchasing a Mac Mini for our office that has some cronjobs setup to periodically backup our resources. I set it up initially and sent it on its way.

About a month and a half into the life of the backups, I noticed that — among other issues — the backup log was quickly becoming very large and I realized we needed to handle log rotation just like our Linux servers’ logs are handled automagically. Unfortunately, OSX does not have the same tools that Linux does for rotating logs… Naturally, being the programmer I am, I thought I’d spend time I don’t have writing a script that I’m sure more than a few people have already written before.

And that’s it! I thought about making it a little more robust initially by allowing the script to handle multiple log files, but again, I didn’t really have time to spend on this anyways so I just made it simple.

If you think you can make it any better, feel free to fork my gist!

--

--