I have need to design a bash script. I'm a little new at it, so I'll do the best I can.
Starting from a base directory, I need to find all of the files in subdirectories of the base. For example, the base would be '/usr/local/var/log/radius/radacct/' So searching in this base, I would need to find files with the name of a file with a date minus one day. For example, try and find all of the 'detail-20121118' files if I ran the script today.
So I have this part:
date=$(date -d "-1 day" +"%Y%m%d")
This will give me the variables for the filename, basedir, and newdir. I then want to do the following:
mv -f "$basedir$filename" "$newdir$filename"
This works. Now on to the complicated part. Starting in /usr/local/var/log/radius/radacct, I have the following structure:
root@radius:/# ls -la /usr/local/var/log/radius/radacct/
drwx------ 5 root root 4096 2012-11-18 12:24 .
drwx------ 3 root root 4096 2011-04-29 08:15 ..
drwxr-xr-x 2 root root 4096 2012-11-19 00:00 10.13.255.13
drwxr-xr-x 2 root root 4096 2012-11-19 00:00 10.13.255.29
drwxr-xr-x 2 root root 4096 2012-11-19 00:00 10.13.255.45
-rw-r--r-- 1 root root 249602219 2012-11-19 17:41 sql-relay
...and searching that directory have this:
root@radius:/# find /usr/local/var/log/radius/radacct/ -name detail-20121118
So basically, anytime you find variable $filename, do stuff (move, then gzip) the file.
Anyone have any pointers until I can get a new server put together and save filespace?