#!/bin/bash . /usr/local/service/sagaApps/bi_saga/dwh_saga/task_day/config.sh if [ -n "$2" ] ;then do_date=$2 else echo "====没有输入数据的日期,取当前时间的前一天====" do_date=$(date -d yesterday +"%Y-%m-%d") fi echo "$do_date" url=$SAGA_URL username=$SAGA_USER password=$SAGA_PASSWORD hdfs_to_mysql() { /usr/local/service/sqoop/bin/sqoop export -D mapred.job.queue.name=hive \ --connect $1 \ --username $2 \ --password $3 \ --table $4 \ -m 1 \ --hcatalog-database saga_dw \ --hcatalog-table $5 \ --fields-terminated-by '\001' \ --input-null-string '\\N' \ --input-null-non-string '\\N' } hdfs_to_mysql_by_day() { /usr/local/service/sqoop/bin/sqoop export -D mapred.job.queue.name=hive \ --connect $1 \ --username $2 \ --password $3 \ --table $4 \ -m 1 \ --hcatalog-database saga_dw \ --hcatalog-table $5 \ --hcatalog-partition-keys dt \ --hcatalog-partition-values $do_date \ --fields-terminated-by '\001' \ --input-null-string '\\N' \ --input-null-non-string '\\N' } app_energy(){ hdfs_to_mysql "$url" "$username" "$password" "app_energy_15_min" "dwd_energy_15_min_hour" } app_energy_day(){ hdfs_to_mysql_by_day "$url" "$username" "$password" "app_energy_15_min" "dwd_energy_15_min_hour" } case $1 in "app_energy") app_energy ;; "app_energy_day") app_energy_day ;; esac