再次调用shell需要时间,我想通过调用hbase shell一次执行多个命令.Below代码只运行单个查询。
cmd="echo \"put 'test', 'row1', 'cf:a', 'value1'\"| hbase shell"
我想在单个hbase shell调用上运行多个查询。
put 'test', 'row1', 'cf:a', 'value1'
put 'test', 'row2', 'cf:b', 'value2'
put 'test', 'row3', 'cf:c', 'value3'
我怎样才能做到这一点?
答案 0 :(得分:6)
我知道有4个选项
选项1:分号
echo "put 'test','row1','cf:a','value1'; put 'test','row2','cf:b','value2'; put 'test','row3','cf:c','value3'" | hbase shell -n
选项2:换行符
echo -e "put 'test','row1','cf:a','value1'\nput 'test','row2','cf:b','value2'\nput 'test','row3','cf:c','value3'" | hbase shell -n
选项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
选项4:外部文件
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
是否包含-n
参数取决于您和您的用例。它指示shell在第一个失败的命令后停止执行,并以非零退出代码退出。它添加了HBASE-11658。
我个人更喜欢选项3,因为它可读并且不需要临时文件。
答案 1 :(得分:3)
尝试将-e
用于echo
:
echo -e "put ...\n put ...\n"