# Creating a temp file to store the output of "list" command.
echo "list" | hbase shell > tableListSummary.txt
# fetch only the list of tables and store it in an another temp file.
tail -1 tableListSummary.txt > tableList.txt
# Separate tables by commas and iterate to perform disable and drop commands.
cat tableList.txt | sed -n 1'p' | tr ',' '\n' | while read word; do
com=$(echo "$word" | sed 's/[][]//g')
table="${com#\"}"
table="${table%\"}"
echo $table
echo "disable '$table'" | hbase shell
echo "drop '$table'" | hbase shell
done
# removing temporary files
rm tableListSummary.txt tableList.txt
5条答案
按热度按时间fv2wmkja1#
如果您使用带有“--non-interactive/-n”选项的hbase版本,则cloudera中的示例:
如果您使用的hbase 1.0.0没有“--非交互式”,则可以从文件中加载命令。hbase文档示例:
mlmc2os52#
shell脚本:deletehbasetables.sh
xbp102n03#
我使用以下方法:
这个
-e
echo的标志使它处理转义序列,这样您就可以在其中构建确认。这个-n
告诉hbase shell这是一个非交互式会话。i1icjdpr4#
在一个文件中输入hbase命令:myfile.txt
运行:“hbase shell<myfile.txt”
观察屏幕上的hbase输出。
或者,将命令中的所有内容输出到一个文件中:“hbase shell<myfile.txt>i想要查看this.log的输出”
wooyq4lh5#
此脚本将从hbase获取所有表,并一次对一个表执行disable和drop操作。
谢谢。