HBase Exit Code – Capture Last Executed Command Status

  • Post author:
  • Post last modified:March 12, 2018
  • Post category:BigData
  • Reading time:3 mins read

You can use HBase exit code to check for success or failure of last executed command in script. These exit code help you to make decision on whether to continue the script execution or abort it in case of command failure. In this article, we have discussed HBase exit code – We have also discussed how to capture last executed command status.

HBase Exit Code – Capture Last Executed Command Status

HBase Exit Code

You can us $? to return the status of last executed command on HBase Shell. Just like other relational databases like Netezza, HBase exit code for last executed command is stored in $?.

When you are running HBase commands interactively at the HBase shell prompt or by using a script (bash or shell), the command returns one of the following exit codes:

  • 0: Command execution successful.
  • 1 or non-zero: Command execution failed.

There is a possibility that, the command could have executed successfully, but the client lost connectivity, or some other event obscured its success. The only way to be sure of the status of an operation is to check. For examples, if you trying to create tables in HBase through script and return code is non-zero exit value, you should verify the HBase for existence of tables. Related posts:

HBase Exit Code Examples

Below examples demonstrates how to capture last executed command status in your script:

Check HBase for existence of available table – Table is available and HBase will return code 0

$ printf "exists '%s'\n" personalnew | hbase shell 2>&1 | grep -q "does exist" 2>/dev/null
$echo $?
0

Check HBase for existence of non-available table – Table is not available and HBase will return non-zero exit codes.

$ printf "exists '%s'\n" personanew | hbase shell 2>&1 | grep -q "does exist" 2>/dev/null
$ echo $?
1

Capture HBase Exit Code in Script

Below is the sample script that demonstrates the HBase exit codes. You will have to use the $? in your shell script to capture the HBase exit code in you custom script. Below shown the sample shell script for reference.

https://gist.github.com/b1640574953ee2de92043cd55ede8b04.js