#!/bin/bash
LocalDir=$(cd `dirname $0`;pwd)
NTIMESTAMP=$(date +%s)
#FTP信息
IPADDR=10.11.12.13
USER=uuu
PASSWORD=ppp
FDIR=/$1
#批次数量
NUM=3
#间隔时间
INTERVAL=1
#$SCRIPT
FTPUP(){
ftp -n<<EOF
open ${IPADDR}
user ${USER} ${PASSWORD}
binary
cd ${FDIR}
prompt off
mput ${UPLISTS[@]}
close
bye
EOF
}
#Process
if [ $# -eq 0 ];then
MAYBEPATH=$(echo ${LocalDir}|sed 's#/#\n#g;/^$/d'|grep "rxtp.*-to-hbase"|awk -F '-' '{print $1}')
echo -e "\n# Please Input FtpPath: ${MAYBEPATH} (Myabe) #\n"
exit
else
while true;do
LISTS=$(ls -lt --time-style '+%s' ${LocalDir}/*.jpg 2>/dev/null|tail -n${NUM}|awk '{print $6","$7}'|sed '/^$/d')
for LISTKEY in ${LISTS[@]};do
OTIMESTAMP=$(echo ${LISTKEY}|awk -F, '{print $1}')
#处理时间间隔
OTIMESTAMP=$(expr ${OTIMESTAMP} + ${INTERVAL})
FILENAME=$(echo ${LISTKEY}|awk -F '/' '{print $NF}')
EXIST=$(grep -wc ${FILENAME} ${LocalDir}/$0.log 2>/dev/null)
if [[ (-z "${EXIST}" || ${EXIST} -eq 0) && ${NTIMESTAMP} -ge ${OTIMESTAMP} ]];then
echo "Add >> "${FILENAME}
UPLISTS=(${UPLISTS[@]} $([ -n "${FILENAME}" ] && echo ${FILENAME}))
echo "${OTIMESTAMP}:${FILENAME}" >> ${LocalDir}/$0.log
fi
done
[ ${#UPLISTS[@]} -eq 0 ] && break || FTPUP
unset UPLISTS
sleep 1
done
fi
05-30