How to run DB2 store procedure from a shell script via root user?

person sticking a post it on a white board with the words how to written on it

If you have used default settings while installing DB2 on AIX. You have created db2inst1 user to use and access DB2. This post is related to the scenario, when a root user have to execute a shell script containing a store procedure of DB2.

Create a shell script with following contents. Your every statement will be run with su to db2inst1.

#!/bin/sh
su - db2inst1 -c 'db2 connect to customerdb user db2inst1 using admin'
su - db2inst1 -c 'db2 -tvsf /u01/IBM/workspace/addcustomer.sql'

Write any thing in your SQL file. I am calling a DB2 store procedure that will insert a row in a table.

call ADDCUSTOMER();

Running being a root user.

bash-3.2# ./addcustomer.sh

   Database Connection Information

 Database server        = DB2/AIX64 9.7.0
 SQL authorization ID   = DB2INST1
 Local database alias   = CUSTOMERDB

call ADDCUSTOMER()

  Return Status = 0

You May Also Like

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.