【问题标题】:Executing sqoop statements from shell script从 shell 脚本执行 sqoop 语句
【发布时间】:2021-09-08 20:14:14
【问题描述】:

我有一个如下所示的输入文件。在第 1 列中具有表名,在该行中剩下的部分是以 ; 结尾的 sqoop 语句。我必须循环表并运行每个 sqoop 语句。我能够读取表格,但由于 sqoop 语句有空格,我无法将整个语句读取为 coulmn2。任何人都可以帮助解决这个问题。

input file
tbl1|sqoop import --options file /location --table tbl1 --target-dir /location --hiveimport ;
tbl2|sqoop import --options file /location --table tbl2 --target-dir /location --hiveimport --compression;
tbl3|sqoop import --options file /location --table tbl3 --target-dir /location --hiveimport --compression;

现在我可以读取输入文件的第一列,但我不知道如何读取整个 sqoop 语句。下面是我尝试过但没有成功的方法。

while read line; do
tbl_name=$(echo "$line"|awk 'BEGIN{FS=","}{print $1}'}
echo "tbl name is $tbl_name" >> "$tbl_name".log
tablestring=${line#"$tbl_name")
for sqoop_statement in ${tablestring//;/ }; do
echo "$sqoop_statement" >> "$tbl_name".log
echo "sqoop statement executed successfully for  $tbl_name" >> "$tbl_name".log
done
done < input.txt

注意:输入文件是自行创建的,可以修改,输入文件中的每一行都有表名,然后是管道分隔符,然后是 sqoop 导入语句,以 ; 结尾。

【问题讨论】:

    标签: linux shell unix scripting sqoop


    【解决方案1】:

    您可以在一行 awk 中实现您正在做的事情。

    awk -F"|" '{print "running the command for "$1"\n"$2" >> "$1".log"; st=system($2">>"$1".log");print (st==0?"Success\n":"Failure\n")}' input.txt
    

    扩展版

    {
        print "running the command for " $1 "\n" $2 " >> " $1 ".log"
        st = system($2 ">>" $1 ".log")
        print (st == 0 ? "Success\n" : "Failure\n")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 2016-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多