Shell script execute SQL file

In this tutorial, How do I use shell script execute SQL file on an Oracle DB? On the server running the shell script, you use a sqlplus command on the server.

You need to install Oracle client on server-run shell script. Example picture below

Shell script execute SQL file

Oracle Client is free, easy to install client software for connecting to Oracle databases.

For example shell script execute SQL file as below

#!/bin/bash

CONNT=dbuser/password@connect_identifier #your env
SQL_FILE=/home/huupv/create_user.sql
sqlplus -s ${CONNT} <<EOF
  @${SQL_FILE}
EOF

RSTATUS=$?
if [ "${RSTATUS}" != "0" ]
then
  echo "Error"
  exit 100
else
  echo "success"
  exit 0
fi

Thank you for reading DevOpsRoles.com page.

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.