#### pull mysql data to local csv file for i in {0..9} do PULL_SQL="SELECT user_id,cid,uid,gid,vid,permanent_city,create_time,update_time,source,date_format(create_time,'%Y-%m-%d') dt from permanent_city_${i};" mysql -h${DB_HOST} -P${DB_PORT} -u${DB_USERNAME} -p${DB_PASSWORD}${DB_NAME} -N -e "${PULL_SQL}" > ${CSV_TMP_DIR}/permanent${i}.csv if [[ $? -eq 0 ]]; then sudo tee -a ${CSV_TMP_DIR}/success.log <<< "${cur_date}####${PULL_SQL} 执行成功..." else sudo tee -a ${CSV_TMP_DIR}/error.log <<< "${cur_date}####${PULL_SQL} 执行失败..." sudo rm -f ${CSV_TMP_DIR}/permanent* exit 1 fi
done
#### put local csv file to hdfs if [[ "`sudo -u ppdev hdfs dfs -ls ${HDFS_LOCATION}`" = "" ]]; then sudo tee -a ${CSV_TMP_DIR}/success.log <<< "${cur_date}####HDFS文件为空..." else sudo tee -a ${CSV_TMP_DIR}/success.log <<< "${cur_date}####HDFS文件不为空..." sudo -u ppdev hdfs dfs -rmr ${HDFS_LOCATION}/permanent* if [[ $? -eq 0 ]]; then sudo tee -a ${CSV_TMP_DIR}/success.log <<< "${cur_date}####HDFS清空旧文件成功..." else sudo tee -a ${CSV_TMP_DIR}/error.log <<< "${cur_date}####HDFS清空旧文件失败..." exit 1 fi fi
sudo -u ppdev hdfs dfs -put ${CSV_TMP_DIR}/permanent* ${HDFS_LOCATION} if [[ $? -eq 0 ]]; then sudo tee -a ${CSV_TMP_DIR}/success.log <<< "${cur_date}####HDFS导入成功..." else sudo tee -a ${CSV_TMP_DIR}/success.log <<< "${cur_date}####HDFS导入失败..." exit 1 fi
#### delete local csv file when put to hdfs success sudo rm -f ${CSV_TMP_DIR}/permanent* if [[ $? -eq 0 ]]; then sudo tee -a ${CSV_TMP_DIR}/success.log <<< "${cur_date}####清空临时CSV文件成功..." else sudo tee -a ${CSV_TMP_DIR}/success.log <<< "${cur_date}####清空临时CSV文件失败..." exit 1 fi