Disable Tomcat Session persistence using sed or perl

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















I need to disable Tomcat session persistence as I have implemented SpringSession on my Spring (not Spring Boot) Application.



I've tried using sed and perl to edit multiple lines in the context.xml file, but none of them have worked. I've tried the following, which do not throw any error, but don't actually do anything:



sed -i 's/<!--n<Manager pathname="" />n-->/<Manager pathname="" />/' /opt/tomcat/conf/context.xml

perl -i -0pe 's/<!--n<Manager pathname="" /> n-->/<Manager pathname="" />/' /opt/tomcat/conf/context.xml


Essentially I want to un-comment the Manager pathname line in context.xml



I want to change:



<!-- Uncomment this to disable session persistence across Tomcat restarts -->

<!--
<Manager pathname="" />
-->


to



<!-- Uncomment this to disable session persistence across Tomcat restarts -->

<Manager pathname="" />









share|improve this question


























    1















    I need to disable Tomcat session persistence as I have implemented SpringSession on my Spring (not Spring Boot) Application.



    I've tried using sed and perl to edit multiple lines in the context.xml file, but none of them have worked. I've tried the following, which do not throw any error, but don't actually do anything:



    sed -i 's/<!--n<Manager pathname="" />n-->/<Manager pathname="" />/' /opt/tomcat/conf/context.xml

    perl -i -0pe 's/<!--n<Manager pathname="" /> n-->/<Manager pathname="" />/' /opt/tomcat/conf/context.xml


    Essentially I want to un-comment the Manager pathname line in context.xml



    I want to change:



    <!-- Uncomment this to disable session persistence across Tomcat restarts -->

    <!--
    <Manager pathname="" />
    -->


    to



    <!-- Uncomment this to disable session persistence across Tomcat restarts -->

    <Manager pathname="" />









    share|improve this question
























      1












      1








      1








      I need to disable Tomcat session persistence as I have implemented SpringSession on my Spring (not Spring Boot) Application.



      I've tried using sed and perl to edit multiple lines in the context.xml file, but none of them have worked. I've tried the following, which do not throw any error, but don't actually do anything:



      sed -i 's/<!--n<Manager pathname="" />n-->/<Manager pathname="" />/' /opt/tomcat/conf/context.xml

      perl -i -0pe 's/<!--n<Manager pathname="" /> n-->/<Manager pathname="" />/' /opt/tomcat/conf/context.xml


      Essentially I want to un-comment the Manager pathname line in context.xml



      I want to change:



      <!-- Uncomment this to disable session persistence across Tomcat restarts -->

      <!--
      <Manager pathname="" />
      -->


      to



      <!-- Uncomment this to disable session persistence across Tomcat restarts -->

      <Manager pathname="" />









      share|improve this question














      I need to disable Tomcat session persistence as I have implemented SpringSession on my Spring (not Spring Boot) Application.



      I've tried using sed and perl to edit multiple lines in the context.xml file, but none of them have worked. I've tried the following, which do not throw any error, but don't actually do anything:



      sed -i 's/<!--n<Manager pathname="" />n-->/<Manager pathname="" />/' /opt/tomcat/conf/context.xml

      perl -i -0pe 's/<!--n<Manager pathname="" /> n-->/<Manager pathname="" />/' /opt/tomcat/conf/context.xml


      Essentially I want to un-comment the Manager pathname line in context.xml



      I want to change:



      <!-- Uncomment this to disable session persistence across Tomcat restarts -->

      <!--
      <Manager pathname="" />
      -->


      to



      <!-- Uncomment this to disable session persistence across Tomcat restarts -->

      <Manager pathname="" />






      sed perl tomcat






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 16:58









      DaithiGDaithiG

      61




      61




















          1 Answer
          1






          active

          oldest

          votes


















          1














          sed and perl by default operate on lines; your problem spans multiple lines. Therefore no match is possible on your input by default. Two common workarounds are either to operate on the entire file at once or to use a state machine that operates by line but keeps track of what has been seen. The entire file method, looking for your data in your input file and keeping only the desired bit:



          $ perl -0777 -ple 's<!--s*(<Manager pathname="" />)s*-->$1' input
          <!-- Uncomment this to disable session persistence across Tomcat restarts -->

          <Manager pathname="" />
          $


          The state machine method is more complicated as there may be other comments that must remain unmolested, and EOF may need special handling if the pattern runs up against that or not; this version prints previously seen lines unless the line is the one we want, in which case the next line is also skipped. You would ideally want unit tests to cover any edge cases possible with such code.



          $ perl -nle 'if (m<Manager pathname="" />) readline else print $prev $prev=$_; END print $prev ' input

          <!-- Uncomment this to disable session persistence across Tomcat restarts -->

          <Manager pathname="" />
          $


          A diff should probably be done afterwards to confirm the edits have changed only what is desired, and then possibly patch used to apply that diff to future editions of the file, which has the advantage of warning about the inability to patch the file and some means to recover from slightly different files.



          $ perl -i.old ..
          $ diff input.old input > input.patch


          A third method would be to fully parse the XML into a tree form in memory and then manipulate that tree to the desired new state and then emit that new form. This has the advantage of being less likely to be thrown off by, say, random whitespace or other changes that cause the above regular expressions to not match (that is, the above methods are more fragile) but will be more complicated to setup, and depending on the parser and emitter used may introduce undesirable changes to the input file.






          share|improve this answer






















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492048%2fdisable-tomcat-session-persistence-using-sed-or-perl%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            sed and perl by default operate on lines; your problem spans multiple lines. Therefore no match is possible on your input by default. Two common workarounds are either to operate on the entire file at once or to use a state machine that operates by line but keeps track of what has been seen. The entire file method, looking for your data in your input file and keeping only the desired bit:



            $ perl -0777 -ple 's<!--s*(<Manager pathname="" />)s*-->$1' input
            <!-- Uncomment this to disable session persistence across Tomcat restarts -->

            <Manager pathname="" />
            $


            The state machine method is more complicated as there may be other comments that must remain unmolested, and EOF may need special handling if the pattern runs up against that or not; this version prints previously seen lines unless the line is the one we want, in which case the next line is also skipped. You would ideally want unit tests to cover any edge cases possible with such code.



            $ perl -nle 'if (m<Manager pathname="" />) readline else print $prev $prev=$_; END print $prev ' input

            <!-- Uncomment this to disable session persistence across Tomcat restarts -->

            <Manager pathname="" />
            $


            A diff should probably be done afterwards to confirm the edits have changed only what is desired, and then possibly patch used to apply that diff to future editions of the file, which has the advantage of warning about the inability to patch the file and some means to recover from slightly different files.



            $ perl -i.old ..
            $ diff input.old input > input.patch


            A third method would be to fully parse the XML into a tree form in memory and then manipulate that tree to the desired new state and then emit that new form. This has the advantage of being less likely to be thrown off by, say, random whitespace or other changes that cause the above regular expressions to not match (that is, the above methods are more fragile) but will be more complicated to setup, and depending on the parser and emitter used may introduce undesirable changes to the input file.






            share|improve this answer



























              1














              sed and perl by default operate on lines; your problem spans multiple lines. Therefore no match is possible on your input by default. Two common workarounds are either to operate on the entire file at once or to use a state machine that operates by line but keeps track of what has been seen. The entire file method, looking for your data in your input file and keeping only the desired bit:



              $ perl -0777 -ple 's<!--s*(<Manager pathname="" />)s*-->$1' input
              <!-- Uncomment this to disable session persistence across Tomcat restarts -->

              <Manager pathname="" />
              $


              The state machine method is more complicated as there may be other comments that must remain unmolested, and EOF may need special handling if the pattern runs up against that or not; this version prints previously seen lines unless the line is the one we want, in which case the next line is also skipped. You would ideally want unit tests to cover any edge cases possible with such code.



              $ perl -nle 'if (m<Manager pathname="" />) readline else print $prev $prev=$_; END print $prev ' input

              <!-- Uncomment this to disable session persistence across Tomcat restarts -->

              <Manager pathname="" />
              $


              A diff should probably be done afterwards to confirm the edits have changed only what is desired, and then possibly patch used to apply that diff to future editions of the file, which has the advantage of warning about the inability to patch the file and some means to recover from slightly different files.



              $ perl -i.old ..
              $ diff input.old input > input.patch


              A third method would be to fully parse the XML into a tree form in memory and then manipulate that tree to the desired new state and then emit that new form. This has the advantage of being less likely to be thrown off by, say, random whitespace or other changes that cause the above regular expressions to not match (that is, the above methods are more fragile) but will be more complicated to setup, and depending on the parser and emitter used may introduce undesirable changes to the input file.






              share|improve this answer

























                1












                1








                1







                sed and perl by default operate on lines; your problem spans multiple lines. Therefore no match is possible on your input by default. Two common workarounds are either to operate on the entire file at once or to use a state machine that operates by line but keeps track of what has been seen. The entire file method, looking for your data in your input file and keeping only the desired bit:



                $ perl -0777 -ple 's<!--s*(<Manager pathname="" />)s*-->$1' input
                <!-- Uncomment this to disable session persistence across Tomcat restarts -->

                <Manager pathname="" />
                $


                The state machine method is more complicated as there may be other comments that must remain unmolested, and EOF may need special handling if the pattern runs up against that or not; this version prints previously seen lines unless the line is the one we want, in which case the next line is also skipped. You would ideally want unit tests to cover any edge cases possible with such code.



                $ perl -nle 'if (m<Manager pathname="" />) readline else print $prev $prev=$_; END print $prev ' input

                <!-- Uncomment this to disable session persistence across Tomcat restarts -->

                <Manager pathname="" />
                $


                A diff should probably be done afterwards to confirm the edits have changed only what is desired, and then possibly patch used to apply that diff to future editions of the file, which has the advantage of warning about the inability to patch the file and some means to recover from slightly different files.



                $ perl -i.old ..
                $ diff input.old input > input.patch


                A third method would be to fully parse the XML into a tree form in memory and then manipulate that tree to the desired new state and then emit that new form. This has the advantage of being less likely to be thrown off by, say, random whitespace or other changes that cause the above regular expressions to not match (that is, the above methods are more fragile) but will be more complicated to setup, and depending on the parser and emitter used may introduce undesirable changes to the input file.






                share|improve this answer













                sed and perl by default operate on lines; your problem spans multiple lines. Therefore no match is possible on your input by default. Two common workarounds are either to operate on the entire file at once or to use a state machine that operates by line but keeps track of what has been seen. The entire file method, looking for your data in your input file and keeping only the desired bit:



                $ perl -0777 -ple 's<!--s*(<Manager pathname="" />)s*-->$1' input
                <!-- Uncomment this to disable session persistence across Tomcat restarts -->

                <Manager pathname="" />
                $


                The state machine method is more complicated as there may be other comments that must remain unmolested, and EOF may need special handling if the pattern runs up against that or not; this version prints previously seen lines unless the line is the one we want, in which case the next line is also skipped. You would ideally want unit tests to cover any edge cases possible with such code.



                $ perl -nle 'if (m<Manager pathname="" />) readline else print $prev $prev=$_; END print $prev ' input

                <!-- Uncomment this to disable session persistence across Tomcat restarts -->

                <Manager pathname="" />
                $


                A diff should probably be done afterwards to confirm the edits have changed only what is desired, and then possibly patch used to apply that diff to future editions of the file, which has the advantage of warning about the inability to patch the file and some means to recover from slightly different files.



                $ perl -i.old ..
                $ diff input.old input > input.patch


                A third method would be to fully parse the XML into a tree form in memory and then manipulate that tree to the desired new state and then emit that new form. This has the advantage of being less likely to be thrown off by, say, random whitespace or other changes that cause the above regular expressions to not match (that is, the above methods are more fragile) but will be more complicated to setup, and depending on the parser and emitter used may introduce undesirable changes to the input file.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 2 at 21:06









                thrigthrig

                24.4k23056




                24.4k23056



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492048%2fdisable-tomcat-session-persistence-using-sed-or-perl%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay