How to limit the log file size created by a Linux service
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
A Linux service is creating a huge log file.
At the moment I am keeping it under control using cron (every X minutes I reduce it to the last X lines):
*/5 * * * * root echo "$(tail -n 1000 /var/log/XXX/logger_file.log)" > /var/log/XXX/logger_file.log
Is there any other way to do the job in a cleaner way?
The first line, after the cut, can even be damaged if the chars cut is size based (i.e. keep the last 1024 bytes).
Of course I cannot modify the service itself to keep quiet.
linux logs
add a comment |Â
up vote
0
down vote
favorite
A Linux service is creating a huge log file.
At the moment I am keeping it under control using cron (every X minutes I reduce it to the last X lines):
*/5 * * * * root echo "$(tail -n 1000 /var/log/XXX/logger_file.log)" > /var/log/XXX/logger_file.log
Is there any other way to do the job in a cleaner way?
The first line, after the cut, can even be damaged if the chars cut is size based (i.e. keep the last 1024 bytes).
Of course I cannot modify the service itself to keep quiet.
linux logs
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
A Linux service is creating a huge log file.
At the moment I am keeping it under control using cron (every X minutes I reduce it to the last X lines):
*/5 * * * * root echo "$(tail -n 1000 /var/log/XXX/logger_file.log)" > /var/log/XXX/logger_file.log
Is there any other way to do the job in a cleaner way?
The first line, after the cut, can even be damaged if the chars cut is size based (i.e. keep the last 1024 bytes).
Of course I cannot modify the service itself to keep quiet.
linux logs
A Linux service is creating a huge log file.
At the moment I am keeping it under control using cron (every X minutes I reduce it to the last X lines):
*/5 * * * * root echo "$(tail -n 1000 /var/log/XXX/logger_file.log)" > /var/log/XXX/logger_file.log
Is there any other way to do the job in a cleaner way?
The first line, after the cut, can even be damaged if the chars cut is size based (i.e. keep the last 1024 bytes).
Of course I cannot modify the service itself to keep quiet.
linux logs
asked Nov 10 '17 at 10:17
Alex Poca
1246
1246
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
Have you tried logrotate? man logrotate
Here is a guide that could help. How to Use logrotate to Manage Log Files
I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
â Alex Poca
Nov 10 '17 at 10:35
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
Have you tried logrotate? man logrotate
Here is a guide that could help. How to Use logrotate to Manage Log Files
I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
â Alex Poca
Nov 10 '17 at 10:35
add a comment |Â
up vote
5
down vote
accepted
Have you tried logrotate? man logrotate
Here is a guide that could help. How to Use logrotate to Manage Log Files
I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
â Alex Poca
Nov 10 '17 at 10:35
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
Have you tried logrotate? man logrotate
Here is a guide that could help. How to Use logrotate to Manage Log Files
Have you tried logrotate? man logrotate
Here is a guide that could help. How to Use logrotate to Manage Log Files
edited Nov 10 '17 at 10:26
GAD3R
22.7k154895
22.7k154895
answered Nov 10 '17 at 10:20
devicehandler
1013
1013
I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
â Alex Poca
Nov 10 '17 at 10:35
add a comment |Â
I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
â Alex Poca
Nov 10 '17 at 10:35
I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
â Alex Poca
Nov 10 '17 at 10:35
I hoped there is a setting somewhere to avoid the use of external commands. If it was system managed it would have dropped extra bytes as soon as the maximum file size was reached, instead of a temporal check with an extra command in cron. Logrotate is powerful indeed. Thank you.
â Alex Poca
Nov 10 '17 at 10:35
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f403725%2fhow-to-limit-the-log-file-size-created-by-a-linux-service%23new-answer', 'question_page');
);
Post as a guest
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
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
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