版权声明:自由转载,无需过问 https://blog.csdn.net/Next__One/article/details/81630509
shell处理HBase命令的执行结果
方法1生成文件
优点:可以更加详细的处理输出结果文件;
缺点:形成很多结果文件,需要有写入权限
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000))
-- 生成毫秒
echo $currentTimeStamp
echo "$1" | hbase shell -n > /root/test/"$currentTimeStamp" 2>&1
-- 拿到HBase命令执行成功还是失败的status:0 成功 1 失败
status=$?
if [ $status -eq 0 ]; then
result=`grep 'row(s) in' /root/test/"$currentTimeStamp"`
else
result=`grep 'ERROR' /root/test/"$currentTimeStamp"`
fi
echo $result
方法2直接处理结果
优点:在有大量输出的时候,只需要保留结果,而不需要存储数据,也不需要写入权限,速度快;
缺点:无法详细处理结果
echo “$1” | hbase shell -n | grep ‘row(s) in|ERROR’ >