Skip to content

Instantly share code, notes, and snippets.

@mgurov
Created January 11, 2016 15:32
Show Gist options
  • Save mgurov/ebb2e98d66048d21c244 to your computer and use it in GitHub Desktop.
Save mgurov/ebb2e98d66048d21c244 to your computer and use it in GitHub Desktop.
waiting for an oracle database to become available
#!/bin/sh -eu
# Wait for port to get available
LOOPS="1000"
PORT=$1
i=0
while ! nc localhost $PORT >/dev/null 2>&1 < /dev/null; do
i=`expr $i + 1`
if [ $i -ge $LOOPS ]; then
echo "$(date) - :${PORT} still not reachable, giving up"
exit 1
fi
echo "$(date) - waiting for :${PORT}..."
sleep 1
done
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=XE
sqlplus -s /nolog <<EOF
connect system/oracle
select CURRENT_TIMESTAMP from DUAL;
quit
EOF
echo "$(date) - port ${PORT} open"
tail -f /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment