#!/bin/bash

export JAVA_HOME=/data/jdk1.8.0_111
export HADOOP_HOME=/data/hadoop-2.6.5
export PATH=${JAVA_HOME}/bin:${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin:$PATH

export JRE_HOME=${JAVA_HOME}/jre
export CLASS_HOME=.:${JAVA_HOME}/lib:${JRE_HOME}/lib

log_src_dir=/home/lpl/logs/log/
log_2_upload_dir=/home/lpl/logs/2upload/

hdfs_log_dir=/data/logs/2018

ls $log_src_dir |while read log_file
do
# if [ "$log_file" = "access.log" ]; then
if [[ "$log_file" == access.log* ]]; then
now=`date "+%Y-%m-%d-%H-%M-%S-%N"`
source_file=$log_src_dir$log_file
target_file=$log_2_upload_dir$now

#cp $source_file $target_file
mv $source_file $target_file

#echo "copy "$source_file" -> "$target_file
echo "move "$source_file" -> "$target_file
fi
done

ls $log_2_upload_dir |grep -v "have_uploaded" |while read log_file
do
now=`date "+%Y-%m-%d.%H:%M:%S.%N"`
source_file=$log_2_upload_dir$log_file
target_file=$log_2_upload_dir"have_uploaded."$now

hadoop fs -put $source_file $hdfs_log_dir
mv $source_file $target_file

echo "move "$source_file" -> "$target_file
done

#ls $log_2_upload_dir |while read log_file do
#echo $log_file
#done