I'm looking for a script that will allow me to programatically modify logrotate configuration files. At the least I'd like it to be able to replace a block such as
/var/log/wtmp {
missingok
monthly
create 0664 root utmp
rotate 1
}
with a new block given on the command line or via stdin or via file (I don't care which). It must be able to operate on arbitrary config files.
I'd really like it if it understood the configuration enough that I could say something like
logrotateupdate /etc/logrotate.conf /var/log/wtmp weekly
and have it do the right thing (remove the monthly and replace it with weekly in the above example).
This may be something that's commonly known to others, but it's something I've never seen.
My system is linux (Ubuntu).
Augeas is the tool for this but it has a fairly steep learning curve. Here's how to set
/var/log/wtmp
to rotate weekly (some/etc/logrotate.conf
trimmed for brevity):There are lenses (as the descriptions of file structures are known) for many configuration files. Writing new lenses isn't too hard once you've got your head around how it all works.
Augeas also ties in nicely with Puppet to make a very powerful configuration management system.
In addition to markdrayton's answer, I'd add that Augeas can now be used as an interpreter, so you can actually write an executable script with the following content:
and execute it. You could even make it shorter by using the autosave option (
-s
):