If I understand fully and correctly, logrotate just compress log files and the number of compressed log files will be growing up after a period of time. It will not delete those outdated compressed log files automatically.
Therefore, I write the following shell script for the captioned purpose which will delete all the files at /var/log and its subdirectories that are existing more than 30 days.
You can change the existing days by altering the value at DAYEXIST.
Step 1 :
nano /home/samiux/cleanup
————- CUT HERE —————–
#!/bin/bash
LOGDIR=”/var/log”
DAYEXIST=”30″
find $LOGDIR -type f -mtime +$DAYEXIST -exec rm {} \;
exit 0
————- CUT HERE —————–
sudo chmod +x /home/samiux/cleanup
Step 2 :
Perform the task at 0130 hours every day.
sudo crontab -e
30 1 * * * /home/samiux/cleanup 2 >&1
Step 3 :
WARNING : DO IT AT YOUR RISK
** Your comment is welcome when my concept is wrong, thanks **
Enjoy!