accweb icon indicating copy to clipboard operation
accweb copied to clipboard

Automatic deletion of old log files.

Open Renegade89 opened this issue 2 years ago • 2 comments

As requested.

I cleaned up about 500MB's of log files today. Is it possible to get this cleaned up f.e. every 7 days, 30 days or any custom interval automatically ? :)

Renegade89 avatar Jul 06 '22 17:07 Renegade89

Hey there, Renegade89.

You can add a cron job or scheduled task that deletes log files older than X days.

Example from my nightly routine on my Linux based server:

#!/bin/bash
echo "Deleting logs older than 2 days from /home/acc."
find /home/acc/ -type f -name "*.log" -mtime +2 -delete

I've put the lines above into somefile.sh, then made it executable with:

chmod +x somefile.sh

Then instructed cron that I want it to run every day at 5:30 AM.

To edit your users cron jobs, run:

crontab -e

Then add the following line, save and exit:

30 5 * * * your_username /path_to/somefile.sh > /dev/null 2>&1

You can omit "> /dev/null 2>&1" if you want the output to be logged.

kslen avatar Nov 24 '23 02:11 kslen

Bit of an old thread, but wanted to share my solution using Windows command line:

del /q /f /s "logs_*.log"

You can run this command from the accweb directory. It will search through all subdirectories, delete all files starting with "logs_" and extension .log.

It will therefore keep the server.log file in the log directory, but delete all the old stuff from the logs directory.

Renegade89 avatar Dec 21 '23 22:12 Renegade89