Dynamic Log Deletion/Rotatoin Script

I've written a small static script for my log deletion, but I was wondering if there was a way to make it a dynamic script. here is how my script currently works.

#!/bin/sh
###########################################
#Script to zip logs older than 1 week old
#and to delete logs older than 30 days old
###########################################
#
##TEST
#
cd /opt/apache/test/logs
find . -name "access_*" -type f -mtime +8 -exec gzip {} \;
find . -name "access_*.gz" -type f -mtime +31 -exec rm {} \;
find . -name "error_*" -type f -mtime +8 -exec gzip {} \;
find . -name "error_*.gz" -type f -mtime +31 -exec rm {} \;
cd /opt/apache/test1/logs
find . -name "access_*" -type f -mtime +8 -exec gzip {} \;
find . -name "access_*.gz" -type f -mtime +31 -exec rm {} \;
find . -name "error_*" -type f -mtime +8 -exec gzip {} \;
find . -name "error_*.gz" -type f -mtime +31 -exec rm {} \;
cd /opt/apache/test2/logs
find . -name "access_*" -type f -mtime +8 -exec gzip {} \;
find . -name "access_*.gz" -type f -mtime +31 -exec rm {} \;
find . -name "error_*" -type f -mtime +8 -exec gzip {} \;
find . -name "error_*.gz" -type f -mtime +31 -exec rm {} \;
echo "Script complete on `date +%D`."

Now for this particular script, i have to simply copy and paste a new block when I create a new apache server, but I figured since the directory structure and log file names are always the same, there would be some way I could add in some actual logic on this.

Possibly cd to /opt/apache/, do a listing, then somehow use an array and a loop to capture the name of each directory in to a variable, and then use that variable to run the find command, do those 4 lines, then if another directory exists repeat.

Hi, use:

find /opt/apache/test*/logs \( -name "access_*.gz" -o -name "error_*.gz" \) -type f -mtime +31 -exec rm {} \;
find /opt/apache/test*/logs \( -name "access_*" -o -name "error_*" \) -type f -mtime +8 -exec gzip {} \;

Regards

The test* directory isn't actually all named test, it's the name of our webservers, and they don't have a normal pattern like that. Can I just substitute an * for test*? To make it

find /opt/apache/*/logs \( -name "access_*.gz" -o -name "error_*.gz" \) -type f -mtime +31 -exec rm {} \;
find /opt/apache/*/logs \( -name "access_*" -o -name "error_*" \) -type f -mtime +8 -exec gzip {} \;

Of course!