#!/bin/bash
#日 月活跃量计算
#auth lilili
#2019-11-28
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
#zookeeper 环境变量
export ZOOKEEPER_HOME=/application/zookeeper
export PATH=$ZOOKEEPER_HOME/bin:$PATH
#hadoop
HADOOP_HOME=/application/hadoop
export HADOOP_HOME
PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
export PATH
#hbash
HBASE_HOME=/application/hbash
export HBASE_HOME
PATH=$HBASE_HOME/bin:$PATH
export PATH
#hive
export HBASE_HOME=/application/hive
export PATH=$HBASE_HOME/bin:$PATH
#sqoop
export HBASE_HOME=/application/sqoop
export PATH=$HBASE_HOME/bin:$PATH
echo "hive running..."
hive --database default -e "
INSERT overwrite TABLE dm_user_event_active
SELECT
FROM_UNIXTIME(unix_timestamp(), 'yyyyMMdd') as tim,
COUNT(DISTINCT ENTERPRISE_CODE) as cou,
'0',
'0'
FROM
dw_user_event
WHERE
day = FROM_UNIXTIME(unix_timestamp(), 'yyyyMMdd')
UNION
SELECT
FROM_UNIXTIME(unix_timestamp(), 'yyyyMM') as tim,
COUNT(DISTINCT ENTERPRISE_CODE) as cou,
'1',
'0'
FROM
dw_user_event
WHERE
month = FROM_UNIXTIME(unix_timestamp(), 'yyyyMM')
;
";
echo "hive stop..."
#sqoopc
echo "sqoop running..."
sqoop export --connect "jdbc:mysql://xxx.xx.xx.67:3306/xxx_xxx?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false" \
--username root --password xxx8888! \
--table dm_user_event_active \
--export-dir /user/hive/warehouse/dm_user_event_active/* --input-fields-terminated-by "\\01" \
--update-mode allowinsert \
--update-key tim;
echo "sqoop stop..."
来源:CSDN
作者:lucklilili
链接:https://blog.csdn.net/lucklilili/article/details/103584446