The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Delete logs daily

Discussion in 'General Discussion' started by JDPWebmaster, Oct 11, 2014.

  1. JDPWebmaster

    JDPWebmaster Member

    Joined:
    Feb 17, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    I'm running CentOS 6.5 along with the latest versions of WHM, Apache and Nginx Admin. I want the following two commands to automatically run once every 24 hours, doesn't matter what time of day. I'm assuming the easiest way to accomplish this is with a cronjob. Can someone please walk me through that process? What would be the correct syntax for the cronjob and where exactly would I create the cronjob?

    Code:
    rm -rf /usr/local/apache/logs/archive/*
    
    rm -rf /var/log/nginx/*
    Any help is appreciated. Thanks in advance!

    P.S. I understand this means once my Apache logs are rotated into /archive they will be permanently deleted within 24 hours. I also understand the same holds true for my Nginx logs. I also realize it's possible to disable the Nginx logs via the Nginx configuration file, which I have done, but it still generates the large microcache.log files which I don't need or want and believe it's easier to just use a cronjob to automatically empty the directory daily!
     
  2. cPanelPeter

    cPanelPeter Technical Analyst III
    Staff Member

    Joined:
    Sep 23, 2013
    Messages:
    569
    Likes Received:
    15
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    This information is available in the crontab man page (specifically the man 5 crontab page).

    Code:
     Instead of the first five fields, one of eight special strings may appear:
    
                  string         meaning
                  ------         -------
                  @reboot        Run once, at startup.
                  @yearly        Run once a year, "0 0 1 1 *".
                  @annually      (same as @yearly)
                  @monthly       Run once a month, "0 0 1 * *".
                  @weekly        Run once a week, "0 0 * * 0".
                  @daily         Run once a day, "0 0 * * *".
                  @midnight      (same as @daily)
                  @hourly        Run once an hour, "0 * * * *".
    
    So you could enter the following from an ssh prompt:

    Code:
    # crontab -e
    
    @daily rm -rf /usr/local/apache/logs/archive/*
    @daily rm -rf /var/log/nginx/*
    
    Out of curiosity, why do you want to do this? Log files are the first thing to examine by any system administrator if something goes wrong. If you remove all log files then you won't be able to determine the cause of a problem later if one comes up.
     
  3. JDPWebmaster

    JDPWebmaster Member

    Joined:
    Feb 17, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    This did the trick! Thank you!
     
Loading...

Share This Page