美文网首页
文件提取脚本

文件提取脚本

作者: 偷油考拉 | 来源:发表于2021-12-17 09:28 被阅读0次

提取某个时间段内的文件,并打包

#!/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 "*****************************************************************************************"

相关文章

网友评论

      本文标题:文件提取脚本

      本文链接:https://www.haomeiwen.com/subject/lmzbfrtx.html