#!/bin/sh
source_dir=/data1/sa
test_dir=/data1/test
remote_dir=/data1/sa
HOST=sftp://192.168.102.1
USER=
PASS=
#源文件比对记录
check_source_file=/data1/check_source_file.txt
if [ ! -f ${check_source_file} ];then
touch ${check_source_file}
fi
# 限定1000条数据
LIMIT_NUM=1000
function cleanLog(){
#源文件清理
LOGFILE=${check_source_file}
POINT_NUM=`cat ${LOGFILE} |wc -l`
if [ ${POINT_NUM} -gt ${LIMIT_NUM} ];then
POINT_NUM=`expr ${POINT_NUM} - ${LIMIT_NUM}`
sed -i "1,${POINT_NUM}d" ${LOGFILE}
fi
}
# 过滤临时文件,查找两分钟内的文件目录
for i in `find ${source_dir} -mmin -2 | grep -v "tmp"`
do
# 获取文件名
file=${i##*/}
echo ${file}
source_nums=`grep -c ${file} ${check_source_file}`
if [ "$source_nums" == "0" ];then
#cp ${source_dir}/${file} /data1/test/
lftp ${HOST} -u ${USER},${PASS} -e "cd ${remote_dir}; put ${source_dir}/${file};quit "
echo "${file}" >> ${check_source_file}
fi
done
# 限定条数
cleanLog
03-11
3698