2 Replies Latest reply on Jul 1, 2015 7:53 PM by jkump

    Crontab to delete log files

    tspwayne


      I have WHD installed on a virtual server. It uses linux and due to lack of space on disc it falls over every few months because of all the log files backups. I was told by support that I can set up a crontab to solve this issue, which I have done today but wanted to check that the commands I have put down are correct.

       

      I edited the crontab with the following:

       

      0 0 * * * /bin/find /usr/local/webhelpdesk/pgsql19/Backups -type f -mtime +7 -exec rm -rf {} \;

       

      using what they had given me as a guide

      0 0 * * * /bin/find /path_to_files -type f -mtime +7 -exec rm -rf {} \;

       

      I saved it

       

      Is this correct or was I meant to change any of the other parts?

       

      It should keep the last 7 days worth

        • Re: Crontab to delete log files
          apap

          Looks like it should be good, deleting every night at midnight.

          If you want to see what will be deleted just run the find part:

          /bin/find /usr/local/webhelpdesk/pgsql19/Backups -type f -mtime +7

            • Re: Crontab to delete log files
              jkump

              always a prudent idea.  Run the script in "safe" mode to find out what is is going to output.  Then when you are sure, go ahead and implement the rest of the script.  You may want to actually run it in the shell before you enable it in the CRONTAB just to be sure what it is going to do.  Just my two cents.....   

               

              Also, you may want to investigate the rotatelogs concept.  Whereby, given the log reaches certain parameters that the logs are automatically closed and compressed and then a new log file opened up.  That way the logs are available for a longer period of times.