Ubuntu logrorate:错误:行必须以关键字或文件名开头(可能是双引号)

Ubuntu logrorate:错误:行必须以关键字或文件名开头(可能是双引号),ubuntu,logrotate,Ubuntu,Logrotate,我的iptables具有以下logrorate配置: /var/log/iptables.log { daily missingok rotate 3 compress notifempty delaycompress postrotate /usr/sbin/service rsynclog restart > /dev/null endscri

我的iptables具有以下logrorate配置:

/var/log/iptables.log {
        daily
        missingok
        rotate 3
        compress
        notifempty
        delaycompress
        postrotate
        /usr/sbin/service rsynclog restart > /dev/null
        endscript
}
当我尝试发出文件语法检查命令时,出现以下错误:

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)

我的配置文件有什么问题?

用LF替换CR线路终端


您应该能够在编辑器中以
Unix
格式保存文件

如果你想从终端解决这个问题,这里有很多建议:

例如,您可以尝试以下方法:

dos2unix -b /etc/logrotate.d/iptables
其中
-b
表示备份

或者自己创建备份:

cp /etc/logrotate.d/iptables /etc/logrotate.d/iptables.bak
然后尝试:

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

在上面的链接中还有很多其他的建议。

有没有奇怪的文件编码?例如,您从
文件/etc/logrotate.d/iptables
中得到了什么?请检查文件中的换行符。它们应该是LF(而不是CRLF)。您应该删除回车。@birgire buy使用您的命令I get:/etc/logrotate.d/iptables:ASCII text,带有CR行终止符我只有
ASCII text
,所以回车(CR)很可能是您的问题。您应该以Unix格式保存文件。您是否在Windows中编写文件?在Sublime中,它的视图->行尾。