Hi All,
I have scenario where I need to zip huge number of DB audit log files newer than 90 days and delete anything older than that. If the files are too huge in number,zipping will take long time and causing CPU spikes. To avoid this I wanted to segregate files based on how old they are and then zip them.
Below is the code that i have written to achieve the same:
cnt=`ls -l | wc -l`
if [ cnt -gt 10000 ] ;
w=80
while [ $w -gt 9 ]
do
mkdir -p mv2SA/$ {w}
find . -name "*.aud" -type f -mtime +${w} -exec mv {} mv2SA/${w}\;
w=$((w-10))
done
fi
If i have file count greater than 10000, I will create multiple directories and move the files into them based on their age.
All 80 days older files should go to mv2SA/80
All 70 days older files should go to mv2SA/70
.
.
.
All 10 days older files should go to mv2SA/10
But its not working as intended, all the files going to mv2SA/80 directory only. Rest all directories are remaining empty.
Can you guys help in segregating the files into multiple directories.
Note: Looking for a solution which works on both HPUX & Linux Systems.
Regards,
Veeresham