如何动态地将日期传递给sqoop命令的shell脚本?

时间:2017-03-22 07:57:20

标签: shell hadoop

我使用以下命令处理sqoop导入:

#!/bin/bash
    while IFS=":" read -r server dbname table; do
    sqoop eval --connect jdbc:mysql://$server/$dbname --username root --password cloudera --table mydata --hive-import --hive-table dynpart --check-column id --last-value $(hive -e "select max(id) from dynpart"); --hive-partition-key 'thisday' --hive-partition-value '01-01-2016'
done<tables.txt

我每天都在做分区。 蜂巢表:

create table dynpart(id int, name char(30), city char(30))
  partitioned by(thisday char(10))
  row format delimited
  fields terminated by ','
  stored as textfile
  location '/hive/mytables'
  tblproperties("comment"="partition column: thisday structure is dd-mm-yyyy");

但我不想直接给出分区值,因为我想创建一个sqoop作业并每天运行它。在脚本中,如何动态地将日期值传递给sqoop命令(格式:dd / mm / yyyy)而不是直接给它? 任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:0)

你可以使用shell命令日期来获取它(ubuntu 14.04):

$ date +%d/%m/%Y
22/03/2017

答案 1 :(得分:0)

您可以尝试以下代码

#!/bin/bash
DATE=$(date +"%d-%m-%y")
while IFS=":" read -r server dbname table; do
sqoop eval --connect jdbc:mysql://$server/$dbname --username root --password cloudera --table mydata --hive-import --hive-table dynpart --check-column id --last-value $(hive -e "select max(id) from dynpart"); --hive-partition-key 'thisday' --hive-partition-value $DATE
done<tables.txt

希望这有助于