Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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).

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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):

[root@dev ~]# cat /etc/logrotate.conf 
# trimmed

# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    minsize 1M
    create 0664 root utmp
    rotate 1
}

[root@dev ~]# (echo "set \
  /files/etc/logrotate.conf/rule[file='/var/log/wtmp']/schedule weekly"; \
  echo save) | augtool
Saved 1 file(s)

[root@dev ~]# cat /etc/logrotate.conf 
# trimmed

# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
    weekly
    minsize 1M
    create 0664 root utmp
    rotate 1
}

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.

share|improve this answer
    
This is a little heavier weight than I'd like, but it's LGPL, so it's really usable. If I don't get a more light-weight answer, I'll probably go with it. –  Michael Kohne Sep 15 '09 at 14:27
add comment

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:

#!/usr/bin/augtool -f
set /files/etc/logrotate.conf/rule[file='/var/log/wtmp']/schedule weekly
save

and execute it. You could even make it shorter by using the autosave option (-s):

#!/usr/bin/augtool -sf
set /files/etc/logrotate.conf/rule[file='/var/log/wtmp']/schedule weekly
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.