Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.