Wednesday 8 September 2010

Shell Scripting Example...

First line of a Shell Script:
#!/bin/bash

Initializing Variables (Note no spaces):
SUCCESS=0
FAILURE=1

Reading a conf file (Format LOG_FILE_PATH=/home/logs/xyz):
CONF_FILE_PATH=batch_jobs.conf
LOG_FILE_PATH=$(cat ${CONF_FILE_PATH} | grep LOG_FILE_PATH= | gawk -F = '/./ {print $2}')

Functions (Example function to check if java command exists):

function init
{
echo "Initialising Import Script"

JAVA_EXECUTABLE_LOCATION=$(which ${JAVA_EXECUTABLE})
if [[ -z "${JAVA_EXECUTABLE_LOCATION}" ]] ; then
echo "Unable to execute import script as the import executable [${JAVA_EXECUTABLE}] is not on the path"
exit ${FAILURE}
fi

}

Function: (Execute java command)

App_AAA_BBB_args=$(cat ${CONF_FILE_PATH} | grep App_Align_Sequences_args= | gawk -F = '/./ {print $2}')
App_XXX_YYYY_jar=$(cat ${CONF_FILE_PATH} | grep App_Align_Sequences_jar= | gawk -F = '/./ {print $2}')

function runAppXXXYYYYY
{
echo "java -Xmx4g -jar ${App_XXX_YYYY_jar} ${App_AAA_BBB_args} 2>&1 | tee -a ${LOG_FILE_PATH}/App_App_XXX_YYYY.log"
java -Xmx4g -jar ${App_XXX_YYYY_jar} ${App_AAA_BBB_args} 2>&1 | tee ${LOG_FILE_PATH}/App_XXX_YYYY.log
}

Calling Functions:

init

runAppYYYYXXXX #function name


exit ${SUCCESS}

No comments:

Post a Comment

Azure OpenAI Architecture Patterns & Deployment Patterns

Sharing some useful links that will help customers architect Azure OpenAI solution using the best practices: (1) Azure OpenAI Landing Zone r...