根据文件名的日期格式,删除数据的脚本

  
  
  
  
#!/bin/bash
#date:20130607
#
datadir=`grep datadir /etc/mysql/my.cnf | cut -d" " -f2`
dbname=/mysql_test
set X=""
for i in `seq 0 7`; do
X="$X "$(date -d "$i month ago" +"%y%m")
done
echo $X > time
ls $datadir$dbname | grep "[a|g|p][[:lower:]]{2}_[[:digit:]]{4}_" > a_file
rm -rf nd_file
for time in `cat time`;do
echo $time
grep $time a_file >> nd_file
done
awk '{print NR, $0}' a_file nd_file |sort -k2 | uniq -u -f 1 | sort -k1 |awk '{print $2}' > /tmp/tmp.txt
while read line
do
cd /tmp
rm -rf $datadir$dbname/$line
sleep 1
done </tmp/tmp.txt


你可能感兴趣的:(删除数据)