How to delete logs automatically after a certain time and restart the process that fills up the log file? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)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>?Ubuntu 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+) logsHow to truncate a file that is being written to
How often does castling occur in grandmaster games?
Did pre-Columbian Americans know the spherical shape of the Earth?
How many time has Arya actually used Needle?
Can you force honesty by using the Speak with Dead and Zone of Truth spells together?
What is a more techy Technical Writer job title that isn't cutesy or confusing?
What is the "studentd" process?
Simple HTTP Server
Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?
After Sam didn't return home in the end, were he and Al still friends?
Resize vertical bars (absolute-value symbols)
How does TikZ render an arc?
A proverb that is used to imply that you have unexpectedly faced a big problem
Can humans save crash-landed aliens?
How were pictures turned from film to a big picture in a picture frame before digital scanning?
Putting class ranking in CV, but against dept guidelines
Delete free apps from Play Store library
Is there hard evidence that the grant peer review system performs significantly better than random?
Trying to understand entropy as a novice in thermodynamics
What order were files/directories output in dir?
What is the difference between a "ranged attack" and a "ranged weapon attack"?
What initially awakened the Balrog?
Why do early math courses focus on the cross sections of a cone and not on other 3D objects?
Sally's older brother
Does the Mueller report show a conspiracy between Russia and the Trump Campaign?
How to delete logs automatically after a certain time and restart the process that fills up the log file?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)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>?Ubuntu 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+) logsHow to truncate a file that is being written to
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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
add a comment |
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
add a comment |
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
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
16.04 process log kill nohup
edited Apr 6 at 7:14
Zanna
51.5k13141244
51.5k13141244
asked Apr 2 at 5:13
DEVCNNDEVCNN
1285
1285
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
Solves my problem. Thanks.
– DEVCNN
Apr 2 at 8:02
Useless use ofecho
. Just>logfile.log
– rexkogitans
Apr 2 at 10:36
using "echo" doesn't hurt. it's build-in
– 0x0C4
Apr 2 at 10:38
2
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
Apr 2 at 11:39
1
@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
Apr 2 at 18:14
|
show 4 more comments
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
.
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
Apr 2 at 8:12
3
@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 likelogrotate
. There are a lot of really good reasons things likesyslog
andlogrotate
exist - and you're learning a lot of them.
– Andrew Henle
Apr 2 at 11:42
Sure. I'll look into that.
– DEVCNN
Apr 2 at 13:01
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Solves my problem. Thanks.
– DEVCNN
Apr 2 at 8:02
Useless use ofecho
. Just>logfile.log
– rexkogitans
Apr 2 at 10:36
using "echo" doesn't hurt. it's build-in
– 0x0C4
Apr 2 at 10:38
2
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
Apr 2 at 11:39
1
@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
Apr 2 at 18:14
|
show 4 more comments
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.
Solves my problem. Thanks.
– DEVCNN
Apr 2 at 8:02
Useless use ofecho
. Just>logfile.log
– rexkogitans
Apr 2 at 10:36
using "echo" doesn't hurt. it's build-in
– 0x0C4
Apr 2 at 10:38
2
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
Apr 2 at 11:39
1
@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
Apr 2 at 18:14
|
show 4 more comments
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.
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.
answered Apr 2 at 7:20
0x0C40x0C4
590311
590311
Solves my problem. Thanks.
– DEVCNN
Apr 2 at 8:02
Useless use ofecho
. Just>logfile.log
– rexkogitans
Apr 2 at 10:36
using "echo" doesn't hurt. it's build-in
– 0x0C4
Apr 2 at 10:38
2
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
Apr 2 at 11:39
1
@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
Apr 2 at 18:14
|
show 4 more comments
Solves my problem. Thanks.
– DEVCNN
Apr 2 at 8:02
Useless use ofecho
. Just>logfile.log
– rexkogitans
Apr 2 at 10:36
using "echo" doesn't hurt. it's build-in
– 0x0C4
Apr 2 at 10:38
2
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
Apr 2 at 11:39
1
@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
Apr 2 at 18:14
Solves my problem. Thanks.
– DEVCNN
Apr 2 at 8:02
Solves my problem. Thanks.
– DEVCNN
Apr 2 at 8:02
Useless use of
echo
. Just >logfile.log
– rexkogitans
Apr 2 at 10:36
Useless use of
echo
. Just >logfile.log
– rexkogitans
Apr 2 at 10:36
using "echo" doesn't hurt. it's build-in
– 0x0C4
Apr 2 at 10:38
using "echo" doesn't hurt. it's build-in
– 0x0C4
Apr 2 at 10:38
2
2
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
Apr 2 at 11:39
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
Apr 2 at 11:39
1
1
@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
Apr 2 at 18:14
@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
Apr 2 at 18:14
|
show 4 more comments
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
.
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
Apr 2 at 8:12
3
@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 likelogrotate
. There are a lot of really good reasons things likesyslog
andlogrotate
exist - and you're learning a lot of them.
– Andrew Henle
Apr 2 at 11:42
Sure. I'll look into that.
– DEVCNN
Apr 2 at 13:01
add a comment |
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
.
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
Apr 2 at 8:12
3
@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 likelogrotate
. There are a lot of really good reasons things likesyslog
andlogrotate
exist - and you're learning a lot of them.
– Andrew Henle
Apr 2 at 11:42
Sure. I'll look into that.
– DEVCNN
Apr 2 at 13:01
add a comment |
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
.
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
.
answered Apr 2 at 6:28
mucluxmuclux
3,72511131
3,72511131
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
Apr 2 at 8:12
3
@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 likelogrotate
. There are a lot of really good reasons things likesyslog
andlogrotate
exist - and you're learning a lot of them.
– Andrew Henle
Apr 2 at 11:42
Sure. I'll look into that.
– DEVCNN
Apr 2 at 13:01
add a comment |
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
Apr 2 at 8:12
3
@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 likelogrotate
. There are a lot of really good reasons things likesyslog
andlogrotate
exist - and you're learning a lot of them.
– Andrew Henle
Apr 2 at 11:42
Sure. I'll look into that.
– DEVCNN
Apr 2 at 13:01
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
Apr 2 at 8:12
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
Apr 2 at 8:12
3
3
@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
Apr 2 at 11:42
@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
Apr 2 at 11:42
Sure. I'll look into that.
– DEVCNN
Apr 2 at 13:01
Sure. I'll look into that.
– DEVCNN
Apr 2 at 13:01
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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