How to monitor the size of a file

applescriptautomator

I run a particular abandoned open source project (StreamBaby) on my home media server, a Mac Mini. It's awesome but has one unfortunate issue which occasionally causes the app to generate an absolutely massive error log – like on the order of many tens of gigabytes. Sometimes by the time I notice it, it's well over 100GB. All I have to do is delete it and restart the service and all is fine, but obviously problems can arise if the drive runs out of space due to this.

I'd like to monitor this file and any time it's larger than maybe 10MB, alert me in some fashion (beep, send an email, pop an alert… something). I've found services that will monitor if a file size has changed, but I need to monitor it for a specific size.

Can this be done via Automator, AppleScript, or some other means?

Best Answer

Since symlinking doesn't work you could use a cronjob to just clear the file every now and then.

For that you will need the Terminal. If you are not familiar, here is an introduction.

Use the following command to open the crontab file (just call crontab -e if you want to use vim instead):

EDITOR=nano crontab -e

Insert the following and save the file (with Ctrl-X -> y -> enter). You must change the file to the log file

0 */1 * * * > "/Users/chaos/Library/Logs/SomeLog.log"

Let me explain: 0 */1 * * * means that on every full hour the command will be executed (unless it's turned off of course). See wikipedia for more info.

The command being executed is basically saying "redirect nothing to the file" effectively truncating it to 0 bytes. You may recognize it from echo something > somefile.log.

FYI: The cron daemon will automatically be started by launchd if a cronfile exists.