accweb
accweb copied to clipboard
Automatic deletion of old log files.
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 ? :)
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.
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.