Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question

2 Answers 2

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

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

share|improve this answer

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.

share|improve this answer

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.