帮我写一个shell脚本 ,批量统计hive库名为fdp库下表名模糊匹配db_的表数据量
时间: 2023-08-04 21:35:07 浏览: 57
好的,以下是一个简单的 Shell 脚本,可以实现批量统计 Hive 库名为 fdp 库下表名模糊匹配 db_ 的表数据量:
```bash
#!/bin/bash
# 连接 Hive 的参数
hive_host=<your_hive_host>
hive_port=<your_hive_port>
hive_user=<your_hive_user>
hive_password=<your_hive_password>
# 待统计的库名和表名
db_name=fdp
table_pattern="db_"
# 查询表名
query="use $db_name; show tables like '$table_pattern';"
tables=$(beeline -u "jdbc:hive2://$hive_host:$hive_port/" -n $hive_user -p $hive_password -e "$query" | tail -n +3)
# 统计每个表的数据量
for table in $tables; do
count_query="use $db_name; select count(*) from $table;"
count=$(beeline -u "jdbc:hive2://$hive_host:$hive_port/" -n $hive_user -p $hive_password -e "$count_query" | tail -n +3)
echo "表 $table 的数据量为: $count"
done
```
你可以根据自己的实际情况修改脚本中的参数,然后将其保存为一个 .sh 文件并执行即可。