Skip to content

Instantly share code, notes, and snippets.

@theothermattm
Created February 21, 2019 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theothermattm/15bed523cf60710f1d342fa2d8352105 to your computer and use it in GitHub Desktop.
Save theothermattm/15bed523cf60710f1d342fa2d8352105 to your computer and use it in GitHub Desktop.
Bash script to check health of an oracle instance
# original source based on: https://github.com/fabiohbarbosa/docker-healthcheck-oracle/blob/master/assets/healthcheck.sh
CHECK=$(${ORACLE_HOME}/bin/sqlplus -s ${HEALTHCHECK_USER}/${HEALTHCHECK_PASSWORD}@localhost/${HEALTHCHECK_SERVICE_NAME} as sysdba <<END
--set pagesize 0 feedback off verify off heading off echo off;
-- the simplest type of health check
--select count(*) from dual;
-- this will check if a
SELECT count(*) FROM V\$INSTANCE where INSTANCE_NAME = 'xe' and DATABASE_STATUS = 'ACTIVE';
exit;
END
)
## Number check
#if ! [ "${CHECK}" -eq "${CHECK}" ] 2>/dev/null; then
# echo ${CHECK}
# exit 1
#fi
#
## Exist table check
#if [ ${CHECK} -gt 0 ]; then
# echo "Healthy"
# exit 0
#else
# exit 1
#fi
if [[ ${CHECK} == *"x"* ]]; then
echo "Healthy"
exit 0
else
echo "Unhealthy: ${CHECK}"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment