我在hdfs中有一个基本目录
/用户/a123
hdfs目录a123有嵌套的子目录
/user/a123/folderA/2017-08-17/xyz
/user/a123/folderA/2017-08-18/abc
/user/a123/folderB/2017-08-17
/user/a123/folderB/2017-08-19
/user/a123/folderC/2017-08-17
/user/a123/folderD/2017-08-20/def
/user/a123/folderD/2017-08-17
/user/a123/folderE/2017-08-17/xyz
从基本目录中,我只需要选择第二级目录,即'yyyy-mm-dd'目录,并比较它是否早于2天。
如果超过2天,则将其打印为存档文件&完整的文件夹名。
today=`date +'%s'`
hdfs dfs -ls /user/a123/ | grep "^d" | while read line ; do
dir_date=$(echo ${line} | awk '{print $6}')
difference=$(( ( ${today} - $(date -d ${dir_date} +%s) ) / ( 24*60*60 ) ))
filePath=$(echo ${line} | awk '{print $8}')
if [ ${difference} -lt 2 ]; then
echo "Archive : "${filePath}
else echo "Existing : "${filePath}
fi
done
预期产量:
Archive : /user/a123/folderA/2017-08-17
Archive : /user/a123/folderA/2017-08-18
Archive : /user/a123/folderB/2017-08-17
Existing : /user/a123/folderB/2017-08-19
Archive : /user/a123/folderC/2017-08-17
Existing : /user/a123/folderD/2017-08-20
Archive : /user/a123/folderD/2017-08-17
Archive : /user/a123/folderE/2017-08-17
暂无答案!
目前还没有任何答案,快来回答吧!