shell脚本操作hbase

echo 
"status
create 'testtable','colfaml'
list 'testtable'
put 'testtable','myrow-1','colfaml:q1','value-1'
scan 'testtable',{LIMIT=>10,REVERSED => true }
disable 'testtable'
drop 'testtable'" | hbase_home/bin/hbase shell -n 2>&1
status=$?
echo "The status was " $status
if [ $status == 0 ]; then
    echo "success"
else
    echo "error"
fi

注:

1)2>&1为错误重定向为标准输出1的意思,即命令正确返回0,错误返回1

前面若添加 > /dev/null 即hbase_home/bin/hbase shell -n > /dev/null 2>&1则为将命令输出到只写文件/dev/null,控制台不打印命令输出,且命令正确返回0,错误返回1

2)status=$? 【$? 显示最后命令的退出状态。0表示没有错误,其他任何值表明有错误。】

猜你喜欢

转载自blog.csdn.net/qq_24166417/article/details/106375015