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.

Setting a cron job to delete log files

Discussion in 'General Discussion' started by ESelf2, Feb 27, 2012.

  1. ESelf2

    ESelf2 Registered

    Joined:
    Feb 27, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Setting a cron job to delete log files

    --------------------------------------------------------------------------------

    I have received a few emails from my server provider concerning my drive space being at critical levels. A sample message is: Drive Critical: /dev/mapper/SysVolGroup-LogVolRoot (/) is 95% full

    I'm interested in setting up a cron job to delete old log files every week (or day) but can't come up with the actual command to run. Any help would be greatly appreciated!

    Thanks,
    Emily
     
  2. JayFromEpic

    JayFromEpic Well-Known Member

    Joined:
    Apr 2, 2011
    Messages:
    204
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Scottsdale, AZ
    cPanel Access Level:
    Root Administrator
    I highly suggest deleting the files manually after you review them. I know a lot of server administrators just destroy the logs after a certain time, however I recommend actually skimming through them to see what is happening on your server so you can address minor issues before they become a full scale server crash.
     
  3. NixTree

    NixTree Well-Known Member

    Joined:
    Aug 19, 2010
    Messages:
    386
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gods Own Country
    cPanel Access Level:
    Root Administrator
    Hello,

    It isn't recommended to empty log files in certain periods! Logs are very important for every admins, to track system activities! Are you sure logs are consuming more disk space on your server? If so, what logs exactly?

    Perhaps you track down the exact log which is consuimg more disk space and tune the log rotation for it. If it is not the logs files consuming disk space, there is no point in removing them!

    Thank you,
    Nibin.
     
  4. storminternet

    storminternet Well-Known Member

    Joined:
    Nov 2, 2011
    Messages:
    462
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
  5. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Personally, why remove the log files using rm or a separate cron than the already existing ones related to logrotate? You can simply change this file at /etc/logrotate.conf location:

    Code:
    # see "man logrotate" for details
    # rotate log files weekly
    weekly
    
    # keep 4 weeks worth of backlogs
    rotate 4
    
    # create new (empty) log files after rotating old ones
    create
    
    # use date as a suffix of the rotated file
    dateext
    
    # uncomment this if you want your log files compressed
    #compress
    
    # RPM packages drop log rotation information into this directory
    include /etc/logrotate.d
    
    # no packages own wtmp and btmp -- we'll rotate them here
    /var/log/wtmp {
        monthly
        create 0664 root utmp
            minsize 1M
        rotate 1
    }
    
    /var/log/btmp {
        missingok
        monthly
        create 0600 root utmp
        rotate 1
    }
    
    # system-specific logs may be also be configured here.
    If you do not want to keep weekly log files for 4 weeks archives (so 1 month worth of log files), then please change to daily or keep weekly and reduce the rotate 4 to rotate 1 and possibly enable compression for the log files as well.
     
Loading...

Share This Page