9

I am trying to write some install scripts for when I install/upgrade Ubuntu. I'm having trouble with fixing logrotate.d:

/var/log/ufw.log
{
rotate 7
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
    reload rsyslog >/dev/null 2>&1 || true
endscript
}

I want to change rotate nnn to rotate 99. It must work for nnn to be any number of digits (normally 1 or 2), yet not affect the postrotate line.

I've tried these two but neither does what I need (and I tested with nnn being 1,2 or 3 digits).

sudo sed  's/rotate[0-9]*/rotate 99/' /etc/logrotate.d/ufw
sudo sed  's/^rotate[0-9]/rotate 99/' /etc/logrotate.d/ufw
12

sed 's/rotate [0-9]\+/rotate 99/'

http://www.gnu.org/software/sed/manual/html_node/Regular-Expressions.html

| improve this answer | |
4

rotate[0-9]* replaces rotate followed by zero or more digits, which matches the end of postrotate. rotate[0-9] replaces only one digit. Furthermore you're missing the space after rotate. I think this does what you want; it also handles indented lines:

sudo sed 's/^\( *rotate *\)[0-9][0-9]*/\1 99/' /etc/logrotate.d/ufw

Add the -i option to sed if you want to change the file in place.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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