How to limit the log file size created by a Linux service

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











up vote
0
down vote

favorite












A Linux service is creating a huge log file.



At the moment I am keeping it under control using cron (every X minutes I reduce it to the last X lines):



*/5 * * * * root echo "$(tail -n 1000 /var/log/XXX/logger_file.log)" > /var/log/XXX/logger_file.log


Is there any other way to do the job in a cleaner way?



The first line, after the cut, can even be damaged if the chars cut is size based (i.e. keep the last 1024 bytes).



Of course I cannot modify the service itself to keep quiet.







share|improve this question
























    up vote
    0
    down vote

    favorite












    A Linux service is creating a huge log file.



    At the moment I am keeping it under control using cron (every X minutes I reduce it to the last X lines):



    */5 * * * * root echo "$(tail -n 1000 /var/log/XXX/logger_file.log)" > /var/log/XXX/logger_file.log


    Is there any other way to do the job in a cleaner way?



    The first line, after the cut, can even be damaged if the chars cut is size based (i.e. keep the last 1024 bytes).



    Of course I cannot modify the service itself to keep quiet.







    share|improve this question






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      A Linux service is creating a huge log file.



      At the moment I am keeping it under control using cron (every X minutes I reduce it to the last X lines):



      */5 * * * * root echo "$(tail -n 1000 /var/log/XXX/logger_file.log)" > /var/log/XXX/logger_file.log


      Is there any other way to do the job in a cleaner way?



      The first line, after the cut, can even be damaged if the chars cut is size based (i.e. keep the last 1024 bytes).



      Of course I cannot modify the service itself to keep quiet.







      share|improve this question












      A Linux service is creating a huge log file.



      At the moment I am keeping it under control using cron (every X minutes I reduce it to the last X lines):



      */5 * * * * root echo "$(tail -n 1000 /var/log/XXX/logger_file.log)" > /var/log/XXX/logger_file.log


      Is there any other way to do the job in a cleaner way?



      The first line, after the cut, can even be damaged if the chars cut is size based (i.e. keep the last 1024 bytes).



      Of course I cannot modify the service itself to keep quiet.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 '17 at 10:17









      Alex Poca

      1246




      1246




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          Have you tried logrotate? man logrotate



          Here is a guide that could help. How to Use logrotate to Manage Log Files






          share|improve this answer






















          • I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
            – Alex Poca
            Nov 10 '17 at 10:35











          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          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%2f403725%2fhow-to-limit-the-log-file-size-created-by-a-linux-service%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          5
          down vote



          accepted










          Have you tried logrotate? man logrotate



          Here is a guide that could help. How to Use logrotate to Manage Log Files






          share|improve this answer






















          • I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
            – Alex Poca
            Nov 10 '17 at 10:35















          up vote
          5
          down vote



          accepted










          Have you tried logrotate? man logrotate



          Here is a guide that could help. How to Use logrotate to Manage Log Files






          share|improve this answer






















          • I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
            – Alex Poca
            Nov 10 '17 at 10:35













          up vote
          5
          down vote



          accepted







          up vote
          5
          down vote



          accepted






          Have you tried logrotate? man logrotate



          Here is a guide that could help. How to Use logrotate to Manage Log Files






          share|improve this answer














          Have you tried logrotate? man logrotate



          Here is a guide that could help. How to Use logrotate to Manage Log Files







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 '17 at 10:26









          GAD3R

          22.7k154895




          22.7k154895










          answered Nov 10 '17 at 10:20









          devicehandler

          1013




          1013











          • I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
            – Alex Poca
            Nov 10 '17 at 10:35

















          • I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
            – Alex Poca
            Nov 10 '17 at 10:35
















          I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
          – Alex Poca
          Nov 10 '17 at 10:35





          I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
          – Alex Poca
          Nov 10 '17 at 10:35


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f403725%2fhow-to-limit-the-log-file-size-created-by-a-linux-service%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

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

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?