How can I su from root to db2inst1 and invoke a SQL script, in one line?

蹲街弑〆低调 提交于 2019-12-08 01:31:47

问题


How can I su from root to db2inst1 and invoke a SQL script all in 1 line? I am thinking about something like this:

su db2inst1 | db2 CONNECT TO myDatabase USER db2inst1 USING mypw; db2 -c -i -w -td@ -f /tmp/deploy/sql/My.sql | exit;

Any ideas?


回答1:


You can use the -c or --command=<command> option to execute a command with su. In your case, something like this:

su -c 'db2 CONNECT TO myDatabase USER db2inst1 USING mypw; db2 -c -i -w -td@ -f /tmp/deploy/sql/My.sql' db2inst1



回答2:


if using Solaris and you don't want/can enter password, checkout pfexec.



来源:https://stackoverflow.com/questions/710110/how-can-i-su-from-root-to-db2inst1-and-invoke-a-sql-script-in-one-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!