14

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?

Erik
  • 14,060
  • 49
  • 132
  • 218
  • 1
    Any strange file encoding maybe? What do you get from `file /etc/logrotate.d/iptables` for example? – birgire Mar 10 '14 at 12:29
  • 2
    check the line breaks in the file. They should be LF (not CRLF). You should remove carriage returns. – Céline Aussourd Mar 10 '14 at 14:25
  • 1
    @birgire buy using your command I get: /etc/logrotate.d/iptables: ASCII text, with CR line terminators – Erik Mar 10 '14 at 15:36
  • 1
    I've only `ASCII text` on mine, so the Carrige Returns (CR) are most likely your problem. You should save your file in Unix format. Do you write your file in Windows? – birgire Mar 10 '14 at 16:25

2 Answers2

17

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.

Community
  • 1
  • 1
birgire
  • 11,258
  • 1
  • 31
  • 54
7

Replace CR line terminators by LF

http://www.cyberciti.biz/faq/howto-unix-linux-convert-dos-newlines-cr-lf-unix-text-format/

Céline Aussourd
  • 10,214
  • 4
  • 32
  • 36