logrorate: error: lines must begin with a keyword or a filename (possibly in double quotes)

Erik picture Erik · Mar 8, 2014 · Viewed 11.6k times · Source

I have the following logrorate config for my iptables:

/var/log/iptables.log {
        daily
        missingok
        rotate 3
        compress
        notifempty
        delaycompress
        postrotate
        /usr/sbin/service rsynclog restart > /dev/null
        endscript
}

When I try to issue checking for file syntax I the following error:

sudo logrotate -vf /etc/logrotate.d/iptables

reading config file iptables
reading config info for /var/log/iptables.log 
error: iptables:1 lines must begin with a keyword or a filename (possibly in double quotes)

What's wrong in my config file?

Answer

birgire picture birgire · Mar 10, 2014

You should be able to save your file in a Unix format in your editor.

If you want to solve this from the terminal, there are lot's of suggestions here:

https://superuser.com/questions/52044/convert-crlfs-to-line-feeds-on-linux https://superuser.com/questions/156516/is-there-a-bash-command-to-convert-r-n-to-n http://www.cyberciti.biz/faq/howto-unix-linux-convert-dos-newlines-cr-lf-unix-text-format/

You can for example try this one:

dos2unix -b /etc/logrotate.d/iptables

where -b stands for backup.

Or create a backup yourself:

cp /etc/logrotate.d/iptables /etc/logrotate.d/iptables.bak

and then try:

tr -d '\r' < /etc/logrotate.d/iptables > /etc/logrotate.d/iptables

There are lot's of other suggestions in the links above.