Mumble Server Log-rotate

I run a Mumble server for my friends and myself. It’s running off of a VPS, so I like to have the log files sent via email for easy access, so I came up with a manual method of emailing and clearing the mumble-server log file using a bash script and cron.

The first thing I wanted the script to do was put the content of the log into the body of an email and send it.


#!/bin/bash
# Mail old log
mail -s "Mumble-server log" [email protected] < \
/var/log/mumble-server/mumble-server.log

This sends an email with the subject “Mumble-server log”, a destination of [email protected], and the contents of the log as the body. Now since I like to have the time the log was rotated put into the log, so there will always be at least one line in the email that is sent out. For that, we define a timestamp function and insert it into the log.


# Define a timestamp function.
timestamp() {
 date +'%Y-%m-%d %T'
 }

echo "< *> $(timestamp) Log rotated successfully" > \
/var/log/mumble-server/mumble-server.log

Now just add the script to run daily in cron, and you’re good to go! I have mine set to run around 3:00 every morning, because everyone is usually off the server by then and connect/disconnect pairs won’t be split across emails. Since we sometimes share links via chat, I also patched the server to log messages that are sent, so the email serves as a handy way to find a shared link if I forget to save it.

Leave a Reply

Your email address will not be published.