如何运行sudo的两个命令? [英] how to run two commands in sudo?
问题描述
有什么办法我怎么可以在命令行中运行两个DB2命令? (它将从PHP exec命令调用)
is there any way how I can run two db2 commands from a command line? (it will be called from php exec command)
- DB2连接到TTT (注意,我们需要有连接住了第二个命令
-
DB2 UPDATE联系人设置EMAIL_ADDRESS ='mytestaccount@gmail.com
- db2 connect to ttt (note that we need to have the connection live for the second command
db2 UPDATE CONTACT SET EMAIL_ADDRESS = 'mytestaccount@gmail.com'
须藤-su DB2INST1的DB2 Connect到TTT; DB2更新联系人设置EMAIL_ADDRESS ='mytestaccount@gmail.com
sudo -su db2inst1 db2 connect to ttt; db2 UPDATE CONTACT SET EMAIL_ADDRESS = 'mytestaccount@gmail.com'
第一个命令正确完成,但第二个 SQL1024N数据库连接不存在。 SQLSTATE = 08003
the first command finishes correctly but the second one SQL1024N A database connection does not exist. SQLSTATE=08003
我需要运行这个作为PHP的用户。命令 sudo的-u db2inst1的ID
为 PHP 用户给了我正确的输出。
I need to run this as php user. Command sudo -u db2inst1 id
as php user gives me correct output.
推荐答案
须藤可以通过shell中运行多个命令,例如:
sudo can run multiple commands via a shell, for example:
$ sudo -s -- 'whoami; whoami'
root
root
您的命令会是这样的:
sudo -u db2inst1 -s -- "db2 connect to ttt; db2 UPDATE CONTACT SET EMAIL_ADDRESS = 'mytestaccount@gmail.com'"
如果你的sudo版本不带有-s(显然,它并不如某些选项编译)分号,则可以使用
If your sudo version doesn't work with semicolons with -s (apparently, it doesn't if compiled with certain options), you can use
sudo -- sh -c 'whoami; whoami'
相反,基本上做同样的事情,但让你明确命名的外壳。
instead, which basically does the same thing but makes you name the shell explicitly.
这篇关于如何运行sudo的两个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!