JDPWebmaster

Member
Feb 17, 2010
6
0
51
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!
 

cPanelPeter

Senior Technical Analyst
Staff member
Sep 23, 2013
578
21
143
cPanel Access Level
Root Administrator
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.