How to run DB2 store procedure from a shell script via root user?
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.
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