shell - 检查是否在给定的时间戳范围内创建了目录
问题描述
努力是能够在目录上执行 hadoop fs -ls 格式的日期范围(如 20170517 到 20170521) (/a/b/c/d/e/f/g/h/test/exp_dt=YYYY -MM-DD)。有没有一种方法可以捕获/知道给定日期范围的目录是否在您提供的时间戳范围内。这将有助于区分分区是旧运行还是新运行的相同日期。
eg:
startdate=20180517
enddate=20180521
timestamp1=2018-05-18 13:00
timestamp2=2018-05-22 13:00
inputPath=/a/b/c/d/e/f/g/h/test/
hlsCmd=`hadoop fs -ls $inputPath | awk '{timestamp = $6 ; hourMin = $7 ; path = $8 ; print timestamp; print hourMin; print path; print ","}'`
echo $hlsCmd
ingestFlag=1
startdate=20180517
enddate=20180521
date="$enddate"
dates=()
for (( date="$enddate" , cnt=1, missCnt=0, foundCnt=0 ; $date >= $startdate ; date="$(date --date="$date - 1 days" +'%Y%m%d')" , cnt++));
do
dates+=( "$date" )
if [ $ingestFlag == 1 ]; then
curDate="$(date --date="$date" +'%Y-%m-%d')"
else
curDate="$(date --date="$date" +'%Y/%m/%d')"
fi;
curDateYYYYMMDD="$(date --date="$date" +'%Y%m%d')"
fmeYYYYMM="$(date --date="$date + 1 month" +'%Y%m')"
if echo "$hlsCmd" | grep -q "$curDate" ; then
((foundCnt++))
echo "$inputPath : $curDate found"
# echo "$inputPath : $curDate found" >> $foundFileName;
else
((missCnt++))
echo "$inputPath : $curDate missing $curDateYYYYMMDD"
echo "$inputPath : $curDate missing $curDateYYYYMMDD" >> $missingFileName;
fi;
output:
/a/b/c/d/e/f/g/h/test/ : 2018-05-21 found
/a/b/c/d/e/f/g/h/test/ : 2018-05-20 found
/a/b/c/d/e/f/g/h/test/ : 2018-05-19 found
/a/b/c/d/e/f/g/h/test/ : 2018-05-18 found
/a/b/c/d/e/f/g/h/test/ : 2018-05-17 found
sample output of $hlsCmd=, 2018-06-06 10:33 /a/b/c/d/e/f/g/h/test/exp_dt=2018-06-03 , 2018-06-07 12:30 /a/b/c/d/e/f/g/h/test/exp_dt=2018-06-04 , 2018-06-08 10:48 /a/b/c/d/e/f/g/h/test/exp_dt=2018-06-05 , 2018-06-08 14:38 /a/b/c/d/e/f/g/h/test/exp_dt=2018-06-06 , 2018-06-09 10:23 /a/b/c/d/e/f/g/h/test/exp_dt=2018-06-07 , 2018-06-10 11:13 /a/b/c/d/e/f/g/h/test/exp_dt=2018-06-08 , 2018-06-11 10:43 /a/b/c/d/e/f/g/h/test/exp_dt=2018-06-09 , 2018-06-12 11:16 /a/b/c/d/e/f/g/h/test/exp_dt=2018-06-10
拦截器:问题是上述代码中的 awk 可以与目录的时间戳(YYYY-MM-DD)进行模式匹配并抛出积极的结果。努力是查看某个范围的目录是否属于某个时间戳。请让我知道可以做什么。
解决方案
推荐阅读
- bash - 使用 Bash 搜索 csv 文件中的列,在 txt 文件中找到它,然后如果找到,将第 1 列和第 2 列从第一个 csv 输出到第二个 csv
- c# - 如何从 EF Core 中的存储过程中获取对象列表?
- snakemake - Snakemake 在执行期间退出规则
- asp.net-core - 如何从 Razor 类库中提取视图?
- python - 模块“dtale”没有属性“global_state”
- r - 根据某些条件在 R 中创建新列
- python - ModuleNotFoundError:没有名为“ipytest.magics”的模块
- javascript - 如何将 json 响应传递给函数:“未知”类型的参数不可分配给“任何 []”类型的参数
- apache-kafka - Kafka Connect 是否支持联合?
- amazon-web-services - AWS IAM 条件策略