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
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
New contributor
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
New contributor
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
New contributor
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
New contributor
New contributor
New contributor
asked 22 hours ago
DEVCNNDEVCNN
1285
1285
New contributor
New contributor
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
19 hours ago
Useless use ofecho
. 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
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
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 likelogrotate
. There are a lot of really good reasons things likesyslog
andlogrotate
exist - and you're learning a lot of them.
– Andrew Henle
15 hours ago
Sure. I'll look into that.
– DEVCNN
14 hours ago
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
);
);
DEVCNN is a new contributor. Be nice, and check out our Code of Conduct.
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
19 hours ago
Useless use ofecho
. 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
add a comment |
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
19 hours ago
Useless use ofecho
. 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
add a comment |
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 20 hours ago
0x0C40x0C4
590311
590311
Solves my problem. Thanks.
– DEVCNN
19 hours ago
Useless use ofecho
. 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
add a comment |
Solves my problem. Thanks.
– DEVCNN
19 hours ago
Useless use ofecho
. 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
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
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 likelogrotate
. There are a lot of really good reasons things likesyslog
andlogrotate
exist - and you're learning a lot of them.
– Andrew Henle
15 hours ago
Sure. I'll look into that.
– DEVCNN
14 hours ago
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
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 likelogrotate
. There are a lot of really good reasons things likesyslog
andlogrotate
exist - and you're learning a lot of them.
– Andrew Henle
15 hours ago
Sure. I'll look into that.
– DEVCNN
14 hours ago
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 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 likelogrotate
. There are a lot of really good reasons things likesyslog
andlogrotate
exist - and you're learning a lot of them.
– Andrew Henle
15 hours ago
Sure. I'll look into that.
– DEVCNN
14 hours ago
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
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 likelogrotate
. There are a lot of really good reasons things likesyslog
andlogrotate
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
add a comment |
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.
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.
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