Код: Выделить всё
# query
batch_count_query="SELECT COUNT(*) AS COUNT FROM ${db_name}.${table_name} WHERE BATCH_STATUS = "RUNNING";"
echo "************** $batch_count_query ******************************"
# Invoke the query
resp1=$(hive -e "$batch_count_query")
# return status check
if [ $? -eq 0 ]; then
echo "******************* Command Ran Successfully ******************** "
echo "Return message is ***************** ${resp1} ****************** "
else
echo "******************* Error during the command execution ******************** "
echo "Return message is ***************** ${resp1} ****************** "
exit 1
fi
Теперь я хочу внести некоторые изменения в сценарий. Я хочу использовать часть кода проверки статуса возврата во многих скриптах.
Поэтому я попытался создать функцию в файле session_helper.sh, как показано ниже
Код: Выделить всё
# find return status of the command
command_exec_status ()
{
message=$1
if [ $? -eq 0 ]; then
echo "******************* Command Ran Successfully ******************** "
echo "Return message is ***************** ${message} ****************** "
else
echo "******************* Error during the command execution ******************** "
echo "Return message is ***************** ${message} ****************** "
exit 1
fi
}
Код: Выделить всё
source /home/$USER/session_helper.sh
# query
batch_count_query="SELECT COUNT(*) AS COUNT FROM ${db_name}.${table_name} WHERE BATCH_STATUS = "RUNNING";"
echo "************** $batch_count_query ******************************"
# Invoke the query
resp1=$(hive -e "$batch_count_query")
# find status based on return code
command_exec_status $resp1
Что я здесь делаю не так. Какой метод правильный.
Подробнее здесь: https://stackoverflow.com/questions/792 ... ell-script
Мобильная версия