简体   繁体   English

用 sed 替换 Tomcat 中的服务器头

[英]Replacing Server Header in Tomcat with sed

I'm trying to automatically replace the server header in Apache Tomcat to prevent telling people I am using Apache.我正在尝试自动替换 Apache Tomcat 中的服务器标头,以防止告诉人们我正在使用 Apache。 I'm currently using sed to try to accomplish this.我目前正在使用 sed 来尝试完成此操作。 I am running the below command:我正在运行以下命令:

sed -ir 's/(?<=server=")(.*)(?=")/IAmATeaPot/g' ./checktext.xml sed -ir 's/(?<=server=")(.*)(?=")/IAmATEaPot/g' ./checktext.xml

I am trying change the checktext.xml in the same directory I am running the command which currently reads我正在尝试在运行当前读取的命令的同一目录中更改 checktext.xml

Connector port="8080" ... server="Apache" />连接器端口="8080" ... server="Apache" />

and change it to:并将其更改为:

Connector port="8080" ... server="IAmATeaPot" />连接器端口="8080" ...服务器="IAmATEaPot" />

My regex appropriately captures the string within the quotes and works in regex checkers online, however nothing happens and I get no error.我的正则表达式适当地捕获了引号内的字符串并在线使用正则表达式检查器,但是没有任何反应并且我没有收到任何错误。 Any idea what I am doing wrong?知道我做错了什么吗?

I think this will do a much cleaner job without having to deal with lookaheads and lookbehinds.我认为这会做得更干净,而无需处理前瞻和后视。

s/server="[^"]*"/server="IAmATeapot"/

You're looking for server=" and then 0 or more non- " characters, and then a closing " , and then replacing the entire thing with server="IAmATeapot" .您正在寻找server="然后是 0 个或更多非"字符,然后是一个结束" ,然后用server="IAmATeapot"替换整个内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM