linux:shell:执行hive查询并将返回值赋值给shell变量

linux:shell:执行hive查询并将返回值赋值给shell变量

2023年7月10日发(作者:)

linux:shell:执⾏hive查询并将返回值赋值给shell变量while循环的使⽤,if循环的使⽤,执⾏hive语句并赋值给shell变量

grep过滤⽆效字符的使⽤

#!/bin/bashstart_date=$1end_date=$2company=$3

#while循环的使⽤,注意[] 这两个符号内侧都要留有空格while [ "$start_date" -le "$end_date" ];do current_date=`date -d "$start_date" +%Y-%m-%d` echo $company echo "current_date====$current_date"

#这⾥切记要注意赋值给变量时,=号左右两侧不要有空格!!同时执⾏hive语句,这⾥使⽤反引号给引起来(数字1按键旁边那个符号),以下是直接在本脚本中执⾏hive语句 counts0=`hive -e "set =false;select case when count(1) > 0 then 1 else 0 end count _organizationsnapshot_1 where effectivedate='${current_date}' and company='${company}';" | grep -v WARN` echo $counts0 #if循环的使⽤ ,注意[] 这两个符号内侧都要留有空格 if [ $counts0 != 1 ];then echo "***********************************************" echo "* $company" echo "* ${current_date} IS NULL THEN INSERT INTO TABLE" echo "***********************************************" #以下是执⾏sql⽂件,⽂件中含有sql语句 hive -hiveconf company=$company -hiveconf current_date=$current_date -f /var/lib/hadoop-hdfs/spride_sqoop_beijing/bi_table/tang/qt/ fi

counts1=`hive -e "set =false;select case when count(1) > 0 then 1 else 0 end count _organizationsnapshot_1 where effectivedate='${current_date}' and company='${company}';" | grep -v WARN`

echo "${current_date}====${counts1}" #if循环的使⽤ ,注意[] 这两个符号内侧都要留有空格 if [ $counts1 == 1 ];then echo "${current_date} IS NOT NULL" start_date=$(date -d "$start_date+1days" +%Y%m%d) else echo "${current_date} IS NULL" fi

done

发布者:admin,转转请注明出处:http://www.yc00.com/news/1688986022a191781.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信