Monday, September 19, 2011

Bulk remove script

A very large number of file needs to be deleted in short period of time.
created following script.

####################################################################
#!/bin/sh
###################################
#Script to delete large number of files. #Amresh Dubey 09192011
#################################
degree=20
inp_name=xxx.aud
FILE_LOC="/p01/oracle/grid/11.2/rdbms/audit"
find ${FILE_LOC} -name '*.aud' -mtime +7 -print > xxx.aud
file_count=`cat ${inp_name} | wc -l`
if [ $file_count ]
then
rm -f file_list*
cp ${inp_name} file_list
mv ${inp_name} ${inp_name}_$(date +"%m%d%y")
split_count=`expr \( $file_count + $file_count % $degree \) / $degree`
split -$split_count file_list file_list_
for list in `ls file_list_*`
do
( for FILE in `cat ${list}`
do
rm -f ${FILE}
echo "Removed $FILE"
done ) > $list$$.log &
done
wait
fi
##############################################################################

No comments: