欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

我的第一个shell脚本

程序员文章站 2022-03-26 09:32:01
我的第一个shell脚本 check.sh use aaaa; set mapreduce.job.queuename=bbbb; --create table zgf_check_ta...

我的第一个shell脚本

check.sh

use aaaa;
set mapreduce.job.queuename=bbbb;

--create table zgf_check_table_pz
--(schema string,
--table_name string,
--lastmodify_time string,
--storage string,
--running_time string)
--row format delimited
--fields terminated by '|'
--stored as textfile;
--
--create table zgf_check_table_pz_tmp
--(schema string,
--table_name string,
--lastmodify_time string,
--storage string,
--running_time string)
--row format delimited
--fields terminated by '|'
--stored as textfile;

insert overwrite table zgf_check_table_pz_tmp
select  schema,table_name,lastmodify_time,storage,running_time from zgf_check_table_pz
where running_time!='${yestoday}';

--载入数据
load data local inpath './log.txt' overwrite into table zgf_check_table_pz;
--插入历史数据
insert into zgf_check_table_pz
select schema,table_name,lastmodify_time,storage,running_time
from zgf_check_table_pz_tmp;

checkcountscript.sh

#!/bin/sh

>./checksql1.sh
>./checksql2.sh
>./checksql3.sh
>./checksql1.txt
>./checksql2.txt
>./checksql3.txt

cat head.txt>checksql1.sh
cat head.txt>checksql2.sh
cat head.txt>checksql3.sh

cat ./tablename.txt | while read line
do
        id=`echo $line |awk -f '|' '{print $1}'`
        table=`echo $line |awk -f '|' '{print $3}'`
        src_table=`echo $line |awk -f '|' '{print $2}'`
        id1=$[ $id % 3]
        echo $id $id1 $table $src_table
        case $id1 in
                                                0) echo hive -e '"'use aaaa";"set mapreduce.job.queuename=bbbb";"select concat"('"$id"','|','"$src_table"','|',count(1))" from $table";"'"'">>"checksql1.txt>>checksql1.sh
                                                ;;
                                                1) echo hive -e '"'use aaaa";"set mapreduce.job.queuename=bbbb";"select concat"('"$id"','|','"$src_table"','|',count(1))" from $table";"'"'">>"checksql2.txt>>checksql2.sh
                                                ;;
                                                2) echo hive -e '"'use aaaa";"set mapreduce.job.queuename=bbbb";"select concat"('"$id"','|','"$src_table"','|',count(1))" from $table";"'"'">>"checksql3.txt>>checksql3.sh
                                                ;;
        esac
done