linux - How to append a string after a string?
淡淡烟草味
淡淡烟草味 2017-06-20 10:06:29
0
2
1476

Hello everyone!

Xiaoxia was recently developed and put forward a requirement: it is necessary to add the intranet IP of the corresponding server to the server.xml file in all modules containing tomcat. An example is as follows:

The excerpt from the original server.xml is as follows:

    <Service name="LMS">
            <Connector port="8080" connectionTimeout="20000" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"  enableLookups="false" disableUploadTimeout="true" maxThreads="500" minSpareThreads="20" acceptCount="100"/>

             <Connector port="8088" connectionTimeout="20000" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"  enableLookups="false" disableUploadTimeout="true" maxThreads="500" minSpareThreads="20" acceptCount="100"/>
                    
            <Connector port="8099" protocol="AJP/1.3" redirectPort="8443" />
            <Engine defaultHost="localhost" name="Catalina">
                     <Realm className="org.apache.catalina.realm.LockOutRealm">
                                    <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase" />
                     </Realm>

Now we need to add the intranet IP to the sentence <Connector port="8099" protocol="AJP/1.3" redirectPort="8443" /> and change it to this:

<Service name="LMS">
                <Connector port="8080" connectionTimeout="20000" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"  enableLookups="false" disableUploadTimeout="true" maxThreads="500" minSpareThreads="20" acceptCount="100"/>

                 <Connector port="8088" connectionTimeout="20000" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"  enableLookups="false" disableUploadTimeout="true" maxThreads="500" minSpareThreads="20" acceptCount="100"/>
                        
                <Connector port="8099" address="1.2.3.4" protocol="AJP/1.3" redirectPort="8443" />
                <Engine defaultHost="localhost" name="Catalina">
                         <Realm className="org.apache.catalina.realm.LockOutRealm">
                                        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase" />
                         </Realm>

How to do it?

I used sed -i '/^<Connector port="8099"/s/port="8099"/port="8099" address="1.2.3.4"/g' server.xml. This command found that it failed. Match, what should I do at this time?

淡淡烟草味
淡淡烟草味

reply all(2)
滿天的星座
sed -i '/<Connector port="8099"/s/port="8099"/port="8099" address="1.2.3.4"/g' server.xml

Your match is written wrong, don’t ^.

大家讲道理

It can be like this:

sed -i 's@Connector port="8099"@& address="1.2.3.4"@' server.xml
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template