Bash File To Rotate Apache Access and Error On Linux

When running a website you may end up with Apache access and error logs that end up being gigabytes in since when they are not correctly rotated. This issue can be solved by using scripts to automate the rotation of log files. Below is a Bash script that solves this problem on Linux.


# location of your log file

# Location of your error file

# Location where your backups will be stored

# Current date for file renaming
DATE=$(date +"%Y%m%d_%H%M%S")

# Create a backup of the log file

#Truncate access log file
echo "" > $ACCESSFILE

#Truncate error log file
echo "" > $ERRORFILE
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *