shell腳本合並文件內容


#!/usr/bash
curDir=/app/cur
hisDir=/app/his
newDir=/app/new
newFile=xxxx_`date +%Y%m%d%H%M%S`_100.txt
#每天開始合並標志文件的時間點,各業務系統約定的時間點后開始,比如23點30分后
runTime=153000
echo"======腳本開始執行======="

while true
do

hh=`date '+%H%M%S'`
echo"======$hh=======$runTime========="
if [ $hh -gt $runTime ]
then
echo "開始處理 $curDir 目錄下的各子系統標志文件"

ls $curDir/*.txt |
while read file_name
do
echo "${file_name%.*} 合並到 $newFile"
cat $file_name >> $newDir/${newFile##*/}
echo "${file_name%.*} 移到 $hisDir "
mv $file_name $hisDir/${file_name##*/}

done
fi
#半個小時輪詢一次,也可以用crontab來設置定時任務
sleep 1800
done

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM