How to logrotate 1 MB file?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite
1












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?










share|improve this question























  • 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















up vote
0
down vote

favorite
1












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?










share|improve this question























  • 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













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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

















  • 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
















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











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:




  1. schedule the cron job more frequently (say, every minute):



    * * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf


    so that you have at most 60 seconds for the log file to grow before possibly reaching the size limit.




  2. 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.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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:




    1. schedule the cron job more frequently (say, every minute):



      * * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf


      so that you have at most 60 seconds for the log file to grow before possibly reaching the size limit.




    2. 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.






    share|improve this answer
























      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:




      1. schedule the cron job more frequently (say, every minute):



        * * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf


        so that you have at most 60 seconds for the log file to grow before possibly reaching the size limit.




      2. 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.






      share|improve this answer






















        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:




        1. schedule the cron job more frequently (say, every minute):



          * * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf


          so that you have at most 60 seconds for the log file to grow before possibly reaching the size limit.




        2. 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.






        share|improve this answer












        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:




        1. schedule the cron job more frequently (say, every minute):



          * * * * * /usr/sbin/logrotate /app/syslog-ng/custom/conf/syslog-ng-rotate.conf


          so that you have at most 60 seconds for the log file to grow before possibly reaching the size limit.




        2. 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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 22 mins ago









        Jeff Schaller

        33.8k851113




        33.8k851113



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)