Apache logs are big, ugly and a waste of resources, I could not find a single resource anywhere on the internet with a simple to use script. So I decided to go ahead and make one.
First to clear Apache logs we will use the “echo” command and “&&” all that “&&” does is complete next command in sequence if the first command completes successfully , I will use an example with two domains and we will make one executable script to ease your future use. You can add as many domain as you like as long as you follow the format presented below.
I would not run this automatically or on a cron as you may need these logs from time to time to troubleshoot.
First get into your home directory:
cd ~
Now lets make a file, I prefer nano:
nano log
In that file place the following, keep in mind I am using generic variables and paths to my files; your paths may be different:
echo " "> /var/www/vhosts/domain1.com/log/error.log && echo " "> /var/www/vhosts/domain2.com/log/access.log
All this does is echo (copy/input) nothing into the log file, if the first command completes it does the next line then exits.
Last thing we need to do is make it executable:
chmod +x log
You can add another domain by just copying the lines and add to extra “&&”‘s between the copied commands.
To run it:
./log
Any questions leave me a comment!





