美文网首页
提取指定日期范围内的目录

提取指定日期范围内的目录

作者: 偷油考拉 | 来源:发表于2021-10-22 12:05 被阅读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=/vsftpdata/channel/dat
    
    
    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 "*****************************************************************************************"
    
    

    执行方法:

    [root@VM_10_9_centos ~]# ./filter.sh 2021-9-3 2021-9-7
    
    
    -------------------  usage  --------------------
    | SAMPLE:  ./filter.sh 2021-9-3 2021-9-7       |
    -------------------  usage  --------------------
    
    
    *****************************************************************************************
    channel number : A2020080
    *****************************************************************************************
    
    2021-09-07  /vsftpdata/channel/dat/A2020080/email/62100417000
    2021-09-03  /vsftpdata/channel/dat/A2020080/email/62100845531
    2021-09-03  /vsftpdata/channel/dat/A2020080/email/62100845371
    2021-09-03  /vsftpdata/channel/dat/A2020080/email/62100437263
    2021-09-03  /vsftpdata/channel/dat/A2020080/email/62100844715
    2021-09-06  /vsftpdata/channel/dat/A2020080/email/62100384501
    2021-09-03  /vsftpdata/channel/dat/A2020080/email/62100437255
    2021-09-07  /vsftpdata/channel/dat/A2020080/email/62100415793
    2021-09-06  /vsftpdata/channel/dat/A2020080/email/62100384552
    
    *****************************************************************************************
    channel number : A2021085
    *****************************************************************************************
    
    channel A2021085 email/ directory doesnot exist!!
    
    
    
    *****************************************************************************************
    package the dir
    *****************************************************************************************
    
    /tmp/filtertmp/
    /tmp/filtertmp/A2020080/
    /tmp/filtertmp/A2020080/62100417000/
    /tmp/filtertmp/A2020080/62100417000/62100417000.xls
    /tmp/filtertmp/A2020080/62100845531/
    /tmp/filtertmp/A2020080/62100845531/62100845531.xls
    /tmp/filtertmp/A2020080/62100845371/
    /tmp/filtertmp/A2020080/62100845371/62100845371.xls
    /tmp/filtertmp/A2020080/62100437263/
    /tmp/filtertmp/A2020080/62100437263/62100437263.xls
    /tmp/filtertmp/A2020080/62100844715/
    /tmp/filtertmp/A2020080/62100844715/62100844715.xls
    /tmp/filtertmp/A2020080/62100384501/
    /tmp/filtertmp/A2020080/62100384501/62100384501.xls
    /tmp/filtertmp/A2020080/62100437255/
    /tmp/filtertmp/A2020080/62100437255/62100437255.xls
    /tmp/filtertmp/A2020080/62100415793/
    /tmp/filtertmp/A2020080/62100415793/62100415793.xls
    /tmp/filtertmp/A2020080/62100384552/
    /tmp/filtertmp/A2020080/62100384552/62100384552.xls
    
    
    *****************************************************************************************
    The target file is /tmp/filter-2021-10-22.tar.gz , please download
    *****************************************************************************************
    
    

    相关文章

      网友评论

          本文标题:提取指定日期范围内的目录

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