Вопрос

I want to run a DB2 query from shell script. I have a user db2inst1 that's required to execute DB2 statements. I am running an application that uses root user to run the shell script. HERE if I switch user to db2inst1. I can do the job.

Following is my scipt that runs perfect with db2inst1.

#!/bin/sh
db2 "connect to customerdb"
db2 "set schema = db2inst1"
db2 "insert into tbl_customer(name,occupation) values ('Alex','Admin')"

See it like a root has to run it. So root user will let the script to switch user first before executing db commands.

My app will invoke this shell script which will use root user.

How can I switch user in script? I am new to shell scripting.

Это было полезно?

Решение

As you are running as root, you can use:

su dbinst1 -c './your_script arg1 arg2 ...'

Were you not running as root, life would be harder.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top