Shell scripting is one of the widely used scripting language to automate day to day activities. Usually, Linux shells are interactive, they accept command as input from users and execute them. However, it will become repetitive as you have to type in all commands each time on terminal. Instead, you can bundle those commands in shell script. In this article, we will check how to execute HBase Commands from Shell Script with an example.
Why Shell Script is Required?
There are many reasons to use Linux shell scripting:
- It helps you to avoid repetitive work and automate them
- It helps to set up script to for routine backups
- You can monitor system using shell scripts
- You can Add new functionality to the shell using shell scripting
How to Execute HBase Commands from Shell Script?
Many organizations use HBase to handle their transaction data. Shell script allows you to write commands that will automate certain tasks such as creating temporary tables, dropping tables after execution is completed. You can directly call HBase shell from shell scripting. You can even control the execution by capturing HBase exit codes on either Linux or windows.
Related Article
Shell Script to List All tables from HBase
Below Shell script allow you to list all tables available in HBase:
#!/bin/bash
echo 'list' | hbase shell -n
status_code=$?
if [ ${status_code} -ne 0 ]; then
echo "The command may have failed."
fi
Related Article
Create HBase Table from Shell Script
You can automate process of creating HBase table using shell script. Below example demonstrate the HBase table creation using shell scrip.
#!/bin/bash
echo "create 'personal','personal_data'" | hbase shell -n
status_code=$?
if [ ${status_code} -ne 0 ]; then
echo "The command may have failed."
fi
Related Article
Insert Record to HBase Table using Shell Script
You can insert records into HBase shell using Shell script.
For Example,
#!/bin/bash
echo "put 'personal',1,'personal_data:name','Ram'" | hbase shell -n
status_code=$?
if [ ${status_code} -ne 0 ]; then
echo "The command may have failed."
fi
Related Article
Drop Table from HBase
You can automate scrip to drop tables from the HBase using shell script. Below example demonstrate the HBase drop table command from HBase shell.
#!/bin/bash
echo "disable 'personal'" | hbase shell -n
echo "drop 'personal'" | hbase shell -n
status_code=$?
if [ ${status_code} -ne 0 ]; then
echo "The command may have failed."
fi
Related Article
Hope this helps 🙂