提取某个时间段内的文件,并打包
#!/bin/bash
echo
echo
echo "------------------- usage --------------------"
echo "| SAMPLE: ./filter.sh 2021-9-3 2021-9-7 |"
echo "------------------- usage --------------------"
# 输出结果包含 2021-9-3 至 2021-9-6 ,2021-9-7 没有
# 所以,填写参数要 +1 天
echo
echo
start_time=`date -d "$1" +%Y-%m-%d`
end_time=`date -d "$2 +1 day" +%Y-%m-%d`
epartnerimg_dir=/opt/epartnerimg
channel=(A2020080 A2021085)
for i in ${channel[*]}; do
echo "*****************************************************************************************"
echo "channel number : $i"
echo "*****************************************************************************************"
echo
if [ -d $epartnerimg_dir/$i/email/ ]; then
#ls -al $epartnerimg_dir/$i/email/
mkdir -p /tmp/filtertmp/$i/
#echo "find $epartnerimg_dir/$i/email/ -type d -newermt $start_time ! -newermt $end_time"
#find $epartnerimg_dir/$i/email/ -maxdepth 1 -mindepth 1 -type d -newermt $start_time ! -newermt $end_time -printf "%TY-%Tm-%Td %p\n"
#find $epartnerimg_dir/$i/email/ -maxdepth 1 -mindepth 1 -type d -newermt $start_time ! -newermt $end_time |xargs -i cp -rf {} /tmp/filtertmp/$i/
find $epartnerimg_dir/$i/email/ -maxdepth 1 -mindepth 1 -type d -newermt $start_time ! -newermt $end_time -printf "%TY-%Tm-%Td %p\n" -exec cp -rf {} /tmp/filtertmp/$i/ \;
else
echo "channel $i email/ directory doesnot exist!!"
fi
echo
done
echo
echo
echo "*****************************************************************************************"
echo "package the dir"
echo "*****************************************************************************************"
echo
tar Pczvf /tmp/filter-`date +%F`.tar.gz /tmp/filtertmp
rm -rf /tmp/filtertmp/
echo
echo
echo "*****************************************************************************************"
echo "The target file is /tmp/filter-`date +%F`.tar.gz , please download"
echo "*****************************************************************************************"
网友评论