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:
Code:
#!/bin/bash
pre="detail-"
date=$(date -d "-1 day" +"%Y%m%d")
filename=$pre$date
basedir="/usr/local/var/log/radius/radacct/"
newdir="/radlogs/"
This will give me the variables for the filename, basedir, and newdir. I then want to do the following:
Code:
mv -f "$basedir$filename" "$newdir$filename"
gzip $newdir$filename
This works. Now on to the complicated part. Starting in /usr/local/var/log/radius/radacct, I have the following structure:
Code:
root@radius:/# ls -la /usr/local/var/log/radius/radacct/
total 244136
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
root@radius:/
...and searching that directory have this:
Code:
root@radius:/# find /usr/local/var/log/radius/radacct/ -name detail-20121118
/usr/local/var/log/radius/radacct/10.13.255.29/detail-20121118
/usr/local/var/log/radius/radacct/10.13.255.45/detail-20121118
/usr/local/var/log/radius/radacct/10.13.255.13/detail-20121118
root@radius:/#
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?