How to logrotate 1 MB file?

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
To rotate logs after the size grows to 1M, cronjob invokes logrotate every 15 mins, as shown below:
0,15,30,45 * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf
where syslog-ng-rotate.conf is
/app/syslog-ng/custom/output/all_devices.log
size 1M
copytruncate
dateext
dateformat -%Y%m%d-%s
rotate 365
sharedscripts
compress
postrotate
/app/syslog-ng/sbin/syslog-ng-ctl reload
endscript
But the above configuration does not work if file size crosses 1M within 15 minutes.
How to make sure, that file gets rotated immediately after the file size goes to 1M?
cron logrotate
add a comment |Â
up vote
0
down vote
favorite
To rotate logs after the size grows to 1M, cronjob invokes logrotate every 15 mins, as shown below:
0,15,30,45 * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf
where syslog-ng-rotate.conf is
/app/syslog-ng/custom/output/all_devices.log
size 1M
copytruncate
dateext
dateformat -%Y%m%d-%s
rotate 365
sharedscripts
compress
postrotate
/app/syslog-ng/sbin/syslog-ng-ctl reload
endscript
But the above configuration does not work if file size crosses 1M within 15 minutes.
How to make sure, that file gets rotated immediately after the file size goes to 1M?
cron logrotate
Are you saying that logrotate does not work at the next (15-minute-scheduled) cron run? Or that you want it to work between cron runs? You cannot expect logrotate to run when you do not tell it to run..
â Jeff Schaller
31 mins ago
@JeffSchaller I want to invokelogrotateimmediately after file size goes to 1M.. for this knowing the interval t(say 15 mins) to invokelogrotateis not certain....
â overexchange
30 mins ago
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
To rotate logs after the size grows to 1M, cronjob invokes logrotate every 15 mins, as shown below:
0,15,30,45 * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf
where syslog-ng-rotate.conf is
/app/syslog-ng/custom/output/all_devices.log
size 1M
copytruncate
dateext
dateformat -%Y%m%d-%s
rotate 365
sharedscripts
compress
postrotate
/app/syslog-ng/sbin/syslog-ng-ctl reload
endscript
But the above configuration does not work if file size crosses 1M within 15 minutes.
How to make sure, that file gets rotated immediately after the file size goes to 1M?
cron logrotate
To rotate logs after the size grows to 1M, cronjob invokes logrotate every 15 mins, as shown below:
0,15,30,45 * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf
where syslog-ng-rotate.conf is
/app/syslog-ng/custom/output/all_devices.log
size 1M
copytruncate
dateext
dateformat -%Y%m%d-%s
rotate 365
sharedscripts
compress
postrotate
/app/syslog-ng/sbin/syslog-ng-ctl reload
endscript
But the above configuration does not work if file size crosses 1M within 15 minutes.
How to make sure, that file gets rotated immediately after the file size goes to 1M?
cron logrotate
cron logrotate
edited 33 mins ago
asked 40 mins ago
overexchange
327212
327212
Are you saying that logrotate does not work at the next (15-minute-scheduled) cron run? Or that you want it to work between cron runs? You cannot expect logrotate to run when you do not tell it to run..
â Jeff Schaller
31 mins ago
@JeffSchaller I want to invokelogrotateimmediately after file size goes to 1M.. for this knowing the interval t(say 15 mins) to invokelogrotateis not certain....
â overexchange
30 mins ago
add a comment |Â
Are you saying that logrotate does not work at the next (15-minute-scheduled) cron run? Or that you want it to work between cron runs? You cannot expect logrotate to run when you do not tell it to run..
â Jeff Schaller
31 mins ago
@JeffSchaller I want to invokelogrotateimmediately after file size goes to 1M.. for this knowing the interval t(say 15 mins) to invokelogrotateis not certain....
â overexchange
30 mins ago
Are you saying that logrotate does not work at the next (15-minute-scheduled) cron run? Or that you want it to work between cron runs? You cannot expect logrotate to run when you do not tell it to run..
â Jeff Schaller
31 mins ago
Are you saying that logrotate does not work at the next (15-minute-scheduled) cron run? Or that you want it to work between cron runs? You cannot expect logrotate to run when you do not tell it to run..
â Jeff Schaller
31 mins ago
@JeffSchaller I want to invoke
logrotate immediately after file size goes to 1M.. for this knowing the interval t(say 15 mins) to invoke logrotate is not certain....â overexchange
30 mins ago
@JeffSchaller I want to invoke
logrotate immediately after file size goes to 1M.. for this knowing the interval t(say 15 mins) to invoke logrotate is not certain....â overexchange
30 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
logrotate only runs when you tell it to run. If you have a log file that may grow quickly, and you're using cron, I have two suggestions:
schedule the cron job more frequently (say, every minute):
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.confso that you have at most 60 seconds for the log file to grow before possibly reaching the size limit.
If your log file is still growing too quickly each minute, then run logrotate multiple times within each minute; either one immediately after the other:
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf(for example), or:
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf... to give 10 seconds between each call to logrotate. Note that you don't want any individual cron job to take more than 60 seconds, or you'll overlap into the next cron job. Consider wrapping the entire cron job with
timeout:* * * * * timeout 59 sh -c "/usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf"
You'd have to experiment with the timings and number of calls to logrotate for your environment to keep the log file under control.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
logrotate only runs when you tell it to run. If you have a log file that may grow quickly, and you're using cron, I have two suggestions:
schedule the cron job more frequently (say, every minute):
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.confso that you have at most 60 seconds for the log file to grow before possibly reaching the size limit.
If your log file is still growing too quickly each minute, then run logrotate multiple times within each minute; either one immediately after the other:
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf(for example), or:
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf... to give 10 seconds between each call to logrotate. Note that you don't want any individual cron job to take more than 60 seconds, or you'll overlap into the next cron job. Consider wrapping the entire cron job with
timeout:* * * * * timeout 59 sh -c "/usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf"
You'd have to experiment with the timings and number of calls to logrotate for your environment to keep the log file under control.
add a comment |Â
up vote
0
down vote
logrotate only runs when you tell it to run. If you have a log file that may grow quickly, and you're using cron, I have two suggestions:
schedule the cron job more frequently (say, every minute):
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.confso that you have at most 60 seconds for the log file to grow before possibly reaching the size limit.
If your log file is still growing too quickly each minute, then run logrotate multiple times within each minute; either one immediately after the other:
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf(for example), or:
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf... to give 10 seconds between each call to logrotate. Note that you don't want any individual cron job to take more than 60 seconds, or you'll overlap into the next cron job. Consider wrapping the entire cron job with
timeout:* * * * * timeout 59 sh -c "/usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf"
You'd have to experiment with the timings and number of calls to logrotate for your environment to keep the log file under control.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
logrotate only runs when you tell it to run. If you have a log file that may grow quickly, and you're using cron, I have two suggestions:
schedule the cron job more frequently (say, every minute):
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.confso that you have at most 60 seconds for the log file to grow before possibly reaching the size limit.
If your log file is still growing too quickly each minute, then run logrotate multiple times within each minute; either one immediately after the other:
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf(for example), or:
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf... to give 10 seconds between each call to logrotate. Note that you don't want any individual cron job to take more than 60 seconds, or you'll overlap into the next cron job. Consider wrapping the entire cron job with
timeout:* * * * * timeout 59 sh -c "/usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf"
You'd have to experiment with the timings and number of calls to logrotate for your environment to keep the log file under control.
logrotate only runs when you tell it to run. If you have a log file that may grow quickly, and you're using cron, I have two suggestions:
schedule the cron job more frequently (say, every minute):
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.confso that you have at most 60 seconds for the log file to grow before possibly reaching the size limit.
If your log file is still growing too quickly each minute, then run logrotate multiple times within each minute; either one immediately after the other:
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf(for example), or:
* * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf... to give 10 seconds between each call to logrotate. Note that you don't want any individual cron job to take more than 60 seconds, or you'll overlap into the next cron job. Consider wrapping the entire cron job with
timeout:* * * * * timeout 59 sh -c "/usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf; sleep 10; /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf"
You'd have to experiment with the timings and number of calls to logrotate for your environment to keep the log file under control.
answered 22 mins ago
Jeff Schaller
33.8k851113
33.8k851113
add a comment |Â
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%2f475116%2fhow-to-logrotate-1-mb-file%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
Are you saying that logrotate does not work at the next (15-minute-scheduled) cron run? Or that you want it to work between cron runs? You cannot expect logrotate to run when you do not tell it to run..
â Jeff Schaller
31 mins ago
@JeffSchaller I want to invoke
logrotateimmediately after file size goes to 1M.. for this knowing the interval t(say 15 mins) to invokelogrotateis not certain....â overexchange
30 mins ago