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

猜你喜欢

转载自www.cnblogs.com/hqsbrx/p/11061589.html
今日推荐