帮我写一个shell脚本,要求如下:1、通过beeline连接到hive,beeline输出格式不含竖线和加号等分隔符。2、批量统计yinzhou库下表名开头为db_的表的数据量。3、输出一个仅包含表名和数据量的cvs文件
时间: 2024-03-12 21:44:25 浏览: 83
好的,这是一个修改后的Bash脚本:
```bash
#!/bin/bash
# 连接hive
beeline -u jdbc:hive2://localhost:10000 -n username -p password -e "set hive.cli.print.header=false; set hive.resultset.use.unique.column.names=true; set hive.cli.print.current.db=false;"
# 统计表数据量
tables=$(beeline -u jdbc:hive2://localhost:10000 -n username -p password -e "show tables in yinzhou like 'db_*';" | grep -v "INFO" | grep -v "WARN")
# 输出cvs文件
echo "Table Name,Data Size" > db_tables.csv
while read -r table; do
data_size=$(beeline -u jdbc:hive2://localhost:10000 -n username -p password -e "select count(*) from yinzhou.$table;")
echo "$table,$data_size" >> db_tables.csv
done <<< "$tables"
```
这个脚本和之前的脚本很相似,但是设置了不同的输出格式。它会通过beeline连接到hive,并设置输出格式。然后,它会统计yinzhou库下表名开头为db_的表的数据量,并输出到一个cvs文件中。同样要注意替换其中的username和password为您的用户名和密码。
阅读全文
相关推荐















