To invoke shell again takes time , i want to execute multiple commands by invoking hbase shell once.Below code run only single query.
cmd="echo \"put 'test', 'row1', 'cf:a', 'value1'\"| hbase shell"
I want to run multiple queries on single hbase shell call.
put 'test', 'row1', 'cf:a', 'value1'
put 'test', 'row2', 'cf:b', 'value2'
put 'test', 'row3', 'cf:c', 'value3'
how can I achieve this ?
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 << EOF
put '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'" > tmpFile
echo "put 'test', 'row2', 'cf:b', 'value2'" >> tmpFile
echo "put 'test', 'row3', 'cf:c', 'value3'" >> tmpFile
hbase shell -n tmpFile
# obviously this also works: cat tmpFile | hbase shell -n
rm 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.
Try using -e
for echo
:
echo -e "put ...\n put ...\n"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With