【发布时间】:2020-02-05 02:14:01
【问题描述】:
我想修改以下文件:
authorize {
update request {
Monthly-Usage = "%{sql:SELECT COALESCE((SUM(`acctoutputoctets`)), 0) FROM radacct WHERE `username`='%{User-Name}' AND Month(acctupdatetime)=(Month(NOW())) AND Year(acctupdatetime)=Year(NOW())}"
}
filter_username
etc
}
这样就变成了这样(更新请求{...}被去掉了)
authorize {
filter_username
etc
}
我查阅了一些例子并想出了这个,但它不起作用:
sed -i 'N; s/update request {\nMonthly-Usage = "%{sql:SELECT COALESCE((SUM(`acctoutputoctets`)), 0) FROM radacct WHERE `username`='"'"'%{User-Name}'"'"' AND Month(acctupdatetime)=(Month(NOW())) AND Year(acctupdatetime)=Year(NOW())}"\n}//g' /etc/freeradius/3.0/sites-enabled/default
【问题讨论】:
-
是
authorize或update request在文件中的多次出现,您需要保持其他人不变?为什么不像你展示的那样用空白模板重新创建一个新文件?祝你好运。 -
这行得通:
awk '/^}/{f=0} !f; /authorize {/{f=1}' <file>。查看stackoverflow.com/a/58243951/1251660了解更多详情。 -
@shellter 是的,有多个
update request,但只有一个authorize {。谢谢 -
@slayedbylucifer 遗憾的是这行不通。
authorize { ... }中还有其他内容,现在也已删除。