Shell script for executing hbase commands - Deleting all hbase tables Shell script for executing hbase commands - Deleting all hbase tables shell shell

Shell script for executing hbase commands - Deleting all hbase tables


I use the following:

#!/bin/shecho -e "disable_all '.*'\ny" | hbase shell -necho -e "drop_all '.*'\ny" | hbase shell -n

The -e flag to echo causes it to process escape sequences so you can build the confirmation into it. The -n tells hbase shell this is a non-interactive session.


Shell Script : deleteHbaseTables.sh

#!/bin/shecho "disable_all .* " | hbase shell echo "drop_all .* " | hbase shell


This script will fetch all the tables from HBase and perform disable and drop operation on 1 table at a time.

#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 shelldone#removing temporary filesrm tableListSummary.txt tableList.txt

Thanks.