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

Has there ever been an airliner design involving reducing generator load by installing solar panels?

What exploit are these user agents trying to use?

Today is the Center

Is it canonical bit space?

What mechanic is there to disable a threat instead of killing it?

Why is Collection not simply treated as Collection<?>

Alternative to sending password over mail?

Neighboring nodes in the network

Emailing HOD to enhance faculty application

Python: return float 1.0 as int 1 but float 1.5 as float 1.5

What does it mean to describe someone as a butt steak?

Is it inappropriate for a student to attend their mentor's dissertation defense?

Why is the 'in' operator throwing an error with a string literal instead of logging false?

Can one be a co-translator of a book, if he does not know the language that the book is translated into?

Combinations of multiple lists

If a Gelatinous Cube takes up the entire space of a Pit Trap, what happens when a creature falls into the trap but succeeds on the saving throw?

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

Fully-Firstable Anagram Sets

intersection of two sorted vectors in C++

Brothers & sisters

How can I tell someone that I want to be his or her friend?

What to put in ESTA if staying in US for a few days before going on to Canada

Should I tell management that I intend to leave due to bad software development practices?

Infinite Abelian subgroup of infinite non Abelian group example



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






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








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 2 days 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
            2 days ago











          • Useless use of echo. Just >logfile.log

            – rexkogitans
            2 days ago











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

            – 0x0C4
            2 days 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
            2 days 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
            2 days 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
            2 days 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
            2 days ago












          • Sure. I'll look into that.

            – DEVCNN
            2 days 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
            2 days ago











          • Useless use of echo. Just >logfile.log

            – rexkogitans
            2 days ago











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

            – 0x0C4
            2 days 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
            2 days 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
            2 days 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
            2 days ago











          • Useless use of echo. Just >logfile.log

            – rexkogitans
            2 days ago











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

            – 0x0C4
            2 days 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
            2 days 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
            2 days 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 2 days ago









          0x0C40x0C4

          590311




          590311












          • Solves my problem. Thanks.

            – DEVCNN
            2 days ago











          • Useless use of echo. Just >logfile.log

            – rexkogitans
            2 days ago











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

            – 0x0C4
            2 days 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
            2 days 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
            2 days ago


















          • Solves my problem. Thanks.

            – DEVCNN
            2 days ago











          • Useless use of echo. Just >logfile.log

            – rexkogitans
            2 days ago











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

            – 0x0C4
            2 days 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
            2 days 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
            2 days ago

















          Solves my problem. Thanks.

          – DEVCNN
          2 days ago





          Solves my problem. Thanks.

          – DEVCNN
          2 days ago













          Useless use of echo. Just >logfile.log

          – rexkogitans
          2 days ago





          Useless use of echo. Just >logfile.log

          – rexkogitans
          2 days ago













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

          – 0x0C4
          2 days ago





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

          – 0x0C4
          2 days 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
          2 days 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
          2 days 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
          2 days 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
          2 days 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
            2 days 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
            2 days ago












          • Sure. I'll look into that.

            – DEVCNN
            2 days 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
            2 days 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
            2 days ago












          • Sure. I'll look into that.

            – DEVCNN
            2 days 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 2 days ago









          mucluxmuclux

          3,50611131




          3,50611131












          • 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
            2 days 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
            2 days ago












          • Sure. I'll look into that.

            – DEVCNN
            2 days 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
            2 days 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
            2 days ago












          • Sure. I'll look into that.

            – DEVCNN
            2 days 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
          2 days 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
          2 days 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
          2 days 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
          2 days ago














          Sure. I'll look into that.

          – DEVCNN
          2 days ago





          Sure. I'll look into that.

          – DEVCNN
          2 days 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

          Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

          Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

          What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company