Assuming your directory names always start with "serverbackup" followed by the "mmddyy", then this should work:
for file in `ls`;
oldday=`echo $file | cut -c 15,16`;
namechk=`echo $file | cut -c 1,2,3,4,5,6,7,8,9,10,11,12`;
if test -d $file && test "$namechk" == "serverbackup"; then
diff=`expr $thisday - $oldday`
if test $diff -gt 7; then
echo "$file: $diff days old - Removing"
#rm -rf $file
echo "$file: $diff days old"
thisday=`echo $today | cut -c 3,4`
Given a directory with the following contents:
cleanup.sh* serverbackup100404/ serverbackup100704/ serverbackup101004/ testfile
serverbackup100204/ serverbackup100504/ serverbackup100804/ serverbackup101104/ testfile.txt
serverbackup100304/ serverbackup100604/ serverbackup100904/ testdir/
the output would be:
serverbackup100204: 9 days old - Removing
serverbackup100304: 8 days old - Removing
serverbackup100404: 7 days old
serverbackup100504: 6 days old
serverbackup100604: 5 days old
serverbackup100704: 4 days old
serverbackup100804: 3 days old
serverbackup100904: 2 days old
serverbackup101004: 1 days old
serverbackup101104: 0 days old
Notice I left the "rm -rf $file" commented. You should throughly test this before actually enabling that. Placing a dynamic "rm" in a shell script makes me cringe with thoughts of $file somehow ending up being equal to "/" and then getting executed as root.
There is somewhat of a sanity check in place though, since it makes sure the directroy starts with "serverbackup" before it would remove it, but you may still want to include a few more safety nets. Anyway, you should at least get an idea of how you can calculate the difference in the dates on end of the file name.
Oops, that won't work when the month and/or year changes, sorry.