Running multiples query on Hbase shell without calling hbase shell again
There are 4 options I know of
Option 1: semicolons
echo "put 'test','row1','cf:a','value1'; put 'test','row2','cf:b','value2'; put 'test','row3','cf:c','value3'" | hbase shell -n
Option 2: newlines
echo -e "put 'test','row1','cf:a','value1'\nput 'test','row2','cf:b','value2'\nput 'test','row3','cf:c','value3'" | hbase shell -n
Option 3: exec
exec hbase shell -n << EOFput 'test', 'row1', 'cf:a', 'value1'put 'test', 'row2', 'cf:b', 'value2'put 'test', 'row3', 'cf:c', 'value3'EOF
Option 4: external file
echo "put 'test', 'row1', 'cf:a', 'value1'" > tmpFileecho "put 'test', 'row2', 'cf:b', 'value2'" >> tmpFileecho "put 'test', 'row3', 'cf:c', 'value3'" >> tmpFilehbase shell -n tmpFile# obviously this also works: cat tmpFile | hbase shell -nrm tmpFile
Whether to include the -n
argument is up to you and your use case. It instructs the shell to stop executing after the first failed command and exit with a non-zero exit code. It was added with HBASE-11658.
I personally prefer option 3 since it's readable and without the need for a temp file.