Search code examples
hbase

Hbase: execute multiple shell commands in one shot


I have to delete multiple rows in HBase based on key, I did a script like this :

deleteall 'mytable:myscheme', 'mykey'
deleteall 'mytable1:myscheme', 'mykey1'
deleteall 'mytable2:myscheme', 'mykey2'
deleteall 'mytable3:myscheme', 'mykey3'
deleteall 'mytable4:myscheme', 'mykey4'

I now use hbase shell to execute them one by one which is very tiring, I wonder if there is some way to execute all in one time ?


Solution

  • What you could do is to store all those commands in a text file and apply them all together in one call.

    Your deleteall.txt:

    deleteall 'mytable:myscheme', 'mykey'
    deleteall 'mytable1:myscheme', 'mykey1'
    deleteall 'mytable2:myscheme', 'mykey2'
    deleteall 'mytable3:myscheme', 'mykey3'
    deleteall 'mytable4:myscheme', 'mykey4'
    exit // add this line if you want to exit hbase shell at the end
    

    Then run in it the shell

    hbase shell < deleteall.txt
    

    If you want your logs to be stored in a file instead of popping up on your terminal, you could use

    hbase shell < deleteall.txt > myLog.log