How to delete logs automatically after a certain time and restart the process that fills up the log file?How can I find out, which jar-files java is currently running (and their PIDs)?Is there any way to give a tag or nickname to a process so it can be killed invoking kill <tag>?How to kill all processes apart from specific oneUbuntu 16.04 /bin/kill bug?Kill all the other instances of a running process except the very first oneBackground process no longer has access to .db file after I log outnohup parallel and rsync out of memory errorCan't kill processes of a userHow to properly kill a background .sh script that keeps calling something else without “killing myself”/killing all my processes?cupsd is consuming 100% cpu and creating large (832GB+) logs

my venezuela girlfriend wants to travel the USA where i live.what does she need to do and how expensive will it become or how difficult?

In the UK, is it possible to get a referendum by a court decision?

How many wives did king shaul have

Was the old ablative pronoun "med" or "mēd"?

Am I breaking OOP practice with this architecture?

Where would I need my direct neural interface to be implanted?

How to show a landlord what we have in savings?

Placement of More Information/Help Icon button for Radio Buttons

Finding the reason behind the value of the integral.

Send out email when Apex Queueable fails and test it

What is an equivalently powerful replacement spell for the Yuan-Ti's Suggestion spell?

Is there a hemisphere-neutral way of specifying a season?

Is it possible to create a QR code using text?

Why didn't Boeing produce its own regional jet?

Do creatures with a listed speed of "0 ft., fly 30 ft. (hover)" ever touch the ground?

Why were 5.25" floppy drives cheaper than 8"?

Is it a bad idea to plug the other end of ESD strap to wall ground?

Implication of namely

Theorists sure want true answers to this!

Why are UK visa biometrics appointments suspended at USCIS Application Support Centers?

What is a Samsaran Word™?

What is the opposite of "eschatology"?

What are the G forces leaving Earth orbit?

Was the Stack Exchange "Happy April Fools" page fitting with the '90's code?



How to delete logs automatically after a certain time and restart the process that fills up the log file?


How can I find out, which jar-files java is currently running (and their PIDs)?Is there any way to give a tag or nickname to a process so it can be killed invoking kill <tag>?How to kill all processes apart from specific oneUbuntu 16.04 /bin/kill bug?Kill all the other instances of a running process except the very first oneBackground process no longer has access to .db file after I log outnohup parallel and rsync out of memory errorCan't kill processes of a userHow to properly kill a background .sh script that keeps calling something else without “killing myself”/killing all my processes?cupsd is consuming 100% cpu and creating large (832GB+) logs













5















Server is Ubuntu 16.04. I have a process running with nohup that logs into a local file. This file gets big enough to consume 100% disk space. To resolve this I have to kill the process first and then remove the log file. Then i restart the process. How can i resolve this with a script or some other tool?










share|improve this question







New contributor




DEVCNN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    5















    Server is Ubuntu 16.04. I have a process running with nohup that logs into a local file. This file gets big enough to consume 100% disk space. To resolve this I have to kill the process first and then remove the log file. Then i restart the process. How can i resolve this with a script or some other tool?










    share|improve this question







    New contributor




    DEVCNN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      5












      5








      5


      1






      Server is Ubuntu 16.04. I have a process running with nohup that logs into a local file. This file gets big enough to consume 100% disk space. To resolve this I have to kill the process first and then remove the log file. Then i restart the process. How can i resolve this with a script or some other tool?










      share|improve this question







      New contributor




      DEVCNN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      Server is Ubuntu 16.04. I have a process running with nohup that logs into a local file. This file gets big enough to consume 100% disk space. To resolve this I have to kill the process first and then remove the log file. Then i restart the process. How can i resolve this with a script or some other tool?







      16.04 process log kill nohup






      share|improve this question







      New contributor




      DEVCNN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      DEVCNN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      DEVCNN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 22 hours ago









      DEVCNNDEVCNN

      1285




      1285




      New contributor




      DEVCNN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      DEVCNN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      DEVCNN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          2 Answers
          2






          active

          oldest

          votes


















          4














          I guess that you start the script/program with nohup like



          nohup scriptname 1>logfile.log 2>& &


          I would recommend instead of deleting the log file just to clear it with



          echo -n >logfile.log


          If you delete/move an open file it will be written until the process will close the file or the process will end.






          share|improve this answer























          • Solves my problem. Thanks.

            – DEVCNN
            19 hours ago











          • Useless use of echo. Just >logfile.log

            – rexkogitans
            17 hours ago











          • using "echo" doesn't hurt. it's build-in

            – 0x0C4
            17 hours ago






          • 1





            This is an extremely unreliable way to free disk space from a full log file. The process writing to the log file has a current offset, and truncating the file with > doesn't change that offset. The next time the file gets written to, you'll likely get either a sparse file if the underlying filesystem supports sparse file, or you'll wind up with a file the same size, almost entirely full of /NUL characters and taking up the same amount of space.

            – Andrew Henle
            16 hours ago











          • @AndrewHenle this answer is simply wrong since the shell is being used for redirection. However, if the redirection is changed to >> then it works because the log file is opened with O_APPEND. See unix.stackexchange.com/questions/202797/…. In general though, your warning is correct. All log files should be opened with O_APPEND to make rotation easy but alas some programs don't do that.

            – Mark Wagner
            9 hours ago



















          13














          With logrotate you can configure how big a log file may get or after how much time:



          • the log files are rotated (log.n becoming log.n+1, and the last log file being deleted)


          • the current log file is truncated without disturbing the writing process.


          Take a look at man 8 logrotate.






          share|improve this answer























          • Maybe this would have worked if the file wasn't open at the time i run logrotate. It tries renaming the file and fails. nohup keeps streaming data into the log file. So i guess it must be open all the time.

            – DEVCNN
            19 hours ago






          • 2





            @DEVCNN You are learning why using standard output and redirecting it to a log file is just about the worst possible approach to logging. Your log file is tied to the logging process, and you can't do anything about it. The actual solution is to use a proper logging system that would allow you to separate the actual log file from the process and allow you to use tools like logrotate. There are a lot of really good reasons things like syslog and logrotate exist - and you're learning a lot of them.

            – Andrew Henle
            15 hours ago












          • Sure. I'll look into that.

            – DEVCNN
            14 hours ago











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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
          );



          );






          DEVCNN is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1130518%2fhow-to-delete-logs-automatically-after-a-certain-time-and-restart-the-process-th%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4














          I guess that you start the script/program with nohup like



          nohup scriptname 1>logfile.log 2>& &


          I would recommend instead of deleting the log file just to clear it with



          echo -n >logfile.log


          If you delete/move an open file it will be written until the process will close the file or the process will end.






          share|improve this answer























          • Solves my problem. Thanks.

            – DEVCNN
            19 hours ago











          • Useless use of echo. Just >logfile.log

            – rexkogitans
            17 hours ago











          • using "echo" doesn't hurt. it's build-in

            – 0x0C4
            17 hours ago






          • 1





            This is an extremely unreliable way to free disk space from a full log file. The process writing to the log file has a current offset, and truncating the file with > doesn't change that offset. The next time the file gets written to, you'll likely get either a sparse file if the underlying filesystem supports sparse file, or you'll wind up with a file the same size, almost entirely full of /NUL characters and taking up the same amount of space.

            – Andrew Henle
            16 hours ago











          • @AndrewHenle this answer is simply wrong since the shell is being used for redirection. However, if the redirection is changed to >> then it works because the log file is opened with O_APPEND. See unix.stackexchange.com/questions/202797/…. In general though, your warning is correct. All log files should be opened with O_APPEND to make rotation easy but alas some programs don't do that.

            – Mark Wagner
            9 hours ago
















          4














          I guess that you start the script/program with nohup like



          nohup scriptname 1>logfile.log 2>& &


          I would recommend instead of deleting the log file just to clear it with



          echo -n >logfile.log


          If you delete/move an open file it will be written until the process will close the file or the process will end.






          share|improve this answer























          • Solves my problem. Thanks.

            – DEVCNN
            19 hours ago











          • Useless use of echo. Just >logfile.log

            – rexkogitans
            17 hours ago











          • using "echo" doesn't hurt. it's build-in

            – 0x0C4
            17 hours ago






          • 1





            This is an extremely unreliable way to free disk space from a full log file. The process writing to the log file has a current offset, and truncating the file with > doesn't change that offset. The next time the file gets written to, you'll likely get either a sparse file if the underlying filesystem supports sparse file, or you'll wind up with a file the same size, almost entirely full of /NUL characters and taking up the same amount of space.

            – Andrew Henle
            16 hours ago











          • @AndrewHenle this answer is simply wrong since the shell is being used for redirection. However, if the redirection is changed to >> then it works because the log file is opened with O_APPEND. See unix.stackexchange.com/questions/202797/…. In general though, your warning is correct. All log files should be opened with O_APPEND to make rotation easy but alas some programs don't do that.

            – Mark Wagner
            9 hours ago














          4












          4








          4







          I guess that you start the script/program with nohup like



          nohup scriptname 1>logfile.log 2>& &


          I would recommend instead of deleting the log file just to clear it with



          echo -n >logfile.log


          If you delete/move an open file it will be written until the process will close the file or the process will end.






          share|improve this answer













          I guess that you start the script/program with nohup like



          nohup scriptname 1>logfile.log 2>& &


          I would recommend instead of deleting the log file just to clear it with



          echo -n >logfile.log


          If you delete/move an open file it will be written until the process will close the file or the process will end.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 20 hours ago









          0x0C40x0C4

          590311




          590311












          • Solves my problem. Thanks.

            – DEVCNN
            19 hours ago











          • Useless use of echo. Just >logfile.log

            – rexkogitans
            17 hours ago











          • using "echo" doesn't hurt. it's build-in

            – 0x0C4
            17 hours ago






          • 1





            This is an extremely unreliable way to free disk space from a full log file. The process writing to the log file has a current offset, and truncating the file with > doesn't change that offset. The next time the file gets written to, you'll likely get either a sparse file if the underlying filesystem supports sparse file, or you'll wind up with a file the same size, almost entirely full of /NUL characters and taking up the same amount of space.

            – Andrew Henle
            16 hours ago











          • @AndrewHenle this answer is simply wrong since the shell is being used for redirection. However, if the redirection is changed to >> then it works because the log file is opened with O_APPEND. See unix.stackexchange.com/questions/202797/…. In general though, your warning is correct. All log files should be opened with O_APPEND to make rotation easy but alas some programs don't do that.

            – Mark Wagner
            9 hours ago


















          • Solves my problem. Thanks.

            – DEVCNN
            19 hours ago











          • Useless use of echo. Just >logfile.log

            – rexkogitans
            17 hours ago











          • using "echo" doesn't hurt. it's build-in

            – 0x0C4
            17 hours ago






          • 1





            This is an extremely unreliable way to free disk space from a full log file. The process writing to the log file has a current offset, and truncating the file with > doesn't change that offset. The next time the file gets written to, you'll likely get either a sparse file if the underlying filesystem supports sparse file, or you'll wind up with a file the same size, almost entirely full of /NUL characters and taking up the same amount of space.

            – Andrew Henle
            16 hours ago











          • @AndrewHenle this answer is simply wrong since the shell is being used for redirection. However, if the redirection is changed to >> then it works because the log file is opened with O_APPEND. See unix.stackexchange.com/questions/202797/…. In general though, your warning is correct. All log files should be opened with O_APPEND to make rotation easy but alas some programs don't do that.

            – Mark Wagner
            9 hours ago

















          Solves my problem. Thanks.

          – DEVCNN
          19 hours ago





          Solves my problem. Thanks.

          – DEVCNN
          19 hours ago













          Useless use of echo. Just >logfile.log

          – rexkogitans
          17 hours ago





          Useless use of echo. Just >logfile.log

          – rexkogitans
          17 hours ago













          using "echo" doesn't hurt. it's build-in

          – 0x0C4
          17 hours ago





          using "echo" doesn't hurt. it's build-in

          – 0x0C4
          17 hours ago




          1




          1





          This is an extremely unreliable way to free disk space from a full log file. The process writing to the log file has a current offset, and truncating the file with > doesn't change that offset. The next time the file gets written to, you'll likely get either a sparse file if the underlying filesystem supports sparse file, or you'll wind up with a file the same size, almost entirely full of /NUL characters and taking up the same amount of space.

          – Andrew Henle
          16 hours ago





          This is an extremely unreliable way to free disk space from a full log file. The process writing to the log file has a current offset, and truncating the file with > doesn't change that offset. The next time the file gets written to, you'll likely get either a sparse file if the underlying filesystem supports sparse file, or you'll wind up with a file the same size, almost entirely full of /NUL characters and taking up the same amount of space.

          – Andrew Henle
          16 hours ago













          @AndrewHenle this answer is simply wrong since the shell is being used for redirection. However, if the redirection is changed to >> then it works because the log file is opened with O_APPEND. See unix.stackexchange.com/questions/202797/…. In general though, your warning is correct. All log files should be opened with O_APPEND to make rotation easy but alas some programs don't do that.

          – Mark Wagner
          9 hours ago






          @AndrewHenle this answer is simply wrong since the shell is being used for redirection. However, if the redirection is changed to >> then it works because the log file is opened with O_APPEND. See unix.stackexchange.com/questions/202797/…. In general though, your warning is correct. All log files should be opened with O_APPEND to make rotation easy but alas some programs don't do that.

          – Mark Wagner
          9 hours ago














          13














          With logrotate you can configure how big a log file may get or after how much time:



          • the log files are rotated (log.n becoming log.n+1, and the last log file being deleted)


          • the current log file is truncated without disturbing the writing process.


          Take a look at man 8 logrotate.






          share|improve this answer























          • Maybe this would have worked if the file wasn't open at the time i run logrotate. It tries renaming the file and fails. nohup keeps streaming data into the log file. So i guess it must be open all the time.

            – DEVCNN
            19 hours ago






          • 2





            @DEVCNN You are learning why using standard output and redirecting it to a log file is just about the worst possible approach to logging. Your log file is tied to the logging process, and you can't do anything about it. The actual solution is to use a proper logging system that would allow you to separate the actual log file from the process and allow you to use tools like logrotate. There are a lot of really good reasons things like syslog and logrotate exist - and you're learning a lot of them.

            – Andrew Henle
            15 hours ago












          • Sure. I'll look into that.

            – DEVCNN
            14 hours ago















          13














          With logrotate you can configure how big a log file may get or after how much time:



          • the log files are rotated (log.n becoming log.n+1, and the last log file being deleted)


          • the current log file is truncated without disturbing the writing process.


          Take a look at man 8 logrotate.






          share|improve this answer























          • Maybe this would have worked if the file wasn't open at the time i run logrotate. It tries renaming the file and fails. nohup keeps streaming data into the log file. So i guess it must be open all the time.

            – DEVCNN
            19 hours ago






          • 2





            @DEVCNN You are learning why using standard output and redirecting it to a log file is just about the worst possible approach to logging. Your log file is tied to the logging process, and you can't do anything about it. The actual solution is to use a proper logging system that would allow you to separate the actual log file from the process and allow you to use tools like logrotate. There are a lot of really good reasons things like syslog and logrotate exist - and you're learning a lot of them.

            – Andrew Henle
            15 hours ago












          • Sure. I'll look into that.

            – DEVCNN
            14 hours ago













          13












          13








          13







          With logrotate you can configure how big a log file may get or after how much time:



          • the log files are rotated (log.n becoming log.n+1, and the last log file being deleted)


          • the current log file is truncated without disturbing the writing process.


          Take a look at man 8 logrotate.






          share|improve this answer













          With logrotate you can configure how big a log file may get or after how much time:



          • the log files are rotated (log.n becoming log.n+1, and the last log file being deleted)


          • the current log file is truncated without disturbing the writing process.


          Take a look at man 8 logrotate.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 21 hours ago









          mucluxmuclux

          3,47611131




          3,47611131












          • Maybe this would have worked if the file wasn't open at the time i run logrotate. It tries renaming the file and fails. nohup keeps streaming data into the log file. So i guess it must be open all the time.

            – DEVCNN
            19 hours ago






          • 2





            @DEVCNN You are learning why using standard output and redirecting it to a log file is just about the worst possible approach to logging. Your log file is tied to the logging process, and you can't do anything about it. The actual solution is to use a proper logging system that would allow you to separate the actual log file from the process and allow you to use tools like logrotate. There are a lot of really good reasons things like syslog and logrotate exist - and you're learning a lot of them.

            – Andrew Henle
            15 hours ago












          • Sure. I'll look into that.

            – DEVCNN
            14 hours ago

















          • Maybe this would have worked if the file wasn't open at the time i run logrotate. It tries renaming the file and fails. nohup keeps streaming data into the log file. So i guess it must be open all the time.

            – DEVCNN
            19 hours ago






          • 2





            @DEVCNN You are learning why using standard output and redirecting it to a log file is just about the worst possible approach to logging. Your log file is tied to the logging process, and you can't do anything about it. The actual solution is to use a proper logging system that would allow you to separate the actual log file from the process and allow you to use tools like logrotate. There are a lot of really good reasons things like syslog and logrotate exist - and you're learning a lot of them.

            – Andrew Henle
            15 hours ago












          • Sure. I'll look into that.

            – DEVCNN
            14 hours ago
















          Maybe this would have worked if the file wasn't open at the time i run logrotate. It tries renaming the file and fails. nohup keeps streaming data into the log file. So i guess it must be open all the time.

          – DEVCNN
          19 hours ago





          Maybe this would have worked if the file wasn't open at the time i run logrotate. It tries renaming the file and fails. nohup keeps streaming data into the log file. So i guess it must be open all the time.

          – DEVCNN
          19 hours ago




          2




          2





          @DEVCNN You are learning why using standard output and redirecting it to a log file is just about the worst possible approach to logging. Your log file is tied to the logging process, and you can't do anything about it. The actual solution is to use a proper logging system that would allow you to separate the actual log file from the process and allow you to use tools like logrotate. There are a lot of really good reasons things like syslog and logrotate exist - and you're learning a lot of them.

          – Andrew Henle
          15 hours ago






          @DEVCNN You are learning why using standard output and redirecting it to a log file is just about the worst possible approach to logging. Your log file is tied to the logging process, and you can't do anything about it. The actual solution is to use a proper logging system that would allow you to separate the actual log file from the process and allow you to use tools like logrotate. There are a lot of really good reasons things like syslog and logrotate exist - and you're learning a lot of them.

          – Andrew Henle
          15 hours ago














          Sure. I'll look into that.

          – DEVCNN
          14 hours ago





          Sure. I'll look into that.

          – DEVCNN
          14 hours ago










          DEVCNN is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          DEVCNN is a new contributor. Be nice, and check out our Code of Conduct.












          DEVCNN is a new contributor. Be nice, and check out our Code of Conduct.











          DEVCNN is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Ask Ubuntu!


          • 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%2faskubuntu.com%2fquestions%2f1130518%2fhow-to-delete-logs-automatically-after-a-certain-time-and-restart-the-process-th%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

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form