Rotating Syslogs in Ubuntu

I have a server running Ubuntu. Log rotation never worked on it for some reason. The log files were getting pretty hairy so I wanted to delete or rotate them. Specifically, to be safe, I wanted to rotate then delete them.

You’d think this is one of those things Google (by way of the ubuntuforums) would have covered six ways to Sunday. But useful information is surprisingly sparse. See for yourself:

http://www.google.com/search?q=ubuntu+syslog+rotation

Anyway, after an hour of frustration looking in vain for someone to spell out the answer for me, I figured it out.

If you want to manually rotate the files, run this command as root (if not root, sudo it):

$ /etc/cron.daily/sysklogd

That rotates the files. Then I just added it to a cron file:

$ crontab -e
# crontab line
0 2 * * * /etc/cron.daily/sysklogd > /dev/null 2>&1

That seems to have licked it. If you can’t find the sysklogd file, you’ve got greater problems than I had, as that gets installed with ubuntu. I’d imagine you could find a copy on the web.