|
#檔案所在的路徑
xdrBasePath=‘/data/test‘
echo ‘xdr檔案根路徑:‘${xdrBasePath}
for file in ${xdrBasePath}/*.txt.gz;
do
##截取檔案裡面的日期資訊
#1,擷取檔案名稱.包含尾碼
filename=$(basename $file)
echo ‘檔案名稱:‘${filename}
#2,截取時間:TSMTPP2735D20170517142005E981.txt.gz
timeyear=${filename:11:4}
timemonth=${filename:15:2}
timeday=${filename:17:2}
#echo ‘解析出的到年的時間:‘${timeyear}
#echo ‘解析出的到月的時間:‘${timemonth}
#echo ‘解析出的到日的時間:‘${timeday}
yeardirpath=${xdrBasePath}/${timeyear}
monthdirpath=${yeardirpath}/${timemonth}
daydirpath=${monthdirpath}/${timeday}
#echo $yeardirpath
#echo $monthdirpath
#echo $daydirpath
#判斷檔案夾是否存在,不存在就建立
if [ ! -e ${yeardirpath} -o ! -d ${yeardirpath} ]; then
mkdir ${yeardirpath}
fi
if [ ! -e ${monthdirpath} -o ! -d ${monthdirpath} ]; then
mkdir ${monthdirpath}
fi
if [ ! -e ${daydirpath} -o ! -d ${daydirpath} ]; then
mkdir ${daydirpath}
fi
#將檔案移動到改目錄下
mv -f ${xdrBasePath}/${filename} ${daydirpath}
#echo ‘-------------------------‘
done |