【问题标题】:How can I sudo as a different user inside a script如何在脚本中以不同用户的身份 sudo
【发布时间】:2013-06-27 09:00:51
【问题描述】:

目前我使用用户 ID“bob”登录 unix 服务器。但我想在脚本中以不同用户(masteruser)的身份使用 sudo。

我当前的代码是

回显密码 | sudo -S masteruser bash

上面的密码是我的密码,masteruser 是我要连接的用户。 但是执行该行我收到错误“sudo: masteruser: command not found”

你能帮我解决这个问题吗?

【问题讨论】:

  • 您是否以交互方式运行脚本?

标签: unix sudo


【解决方案1】:
echo password | su masteruser -c "echo this is the command you wish to run as masteruser"

【讨论】:

  • 我试过这个命令:echo password | su masteruser -c nohup sh -x /tmp/cron.sh > /tmp/cron.log 2>&1 & .它创建了所有者为 bob 的文件 cron.log,这是错误的。它应该由所有者 masteruser 创建。同样在 cron.log 文件中有错误 su: invalid option -- 'x'。尝试使用 `su --help' 获取更多信息。
猜你喜欢
  • 1970-01-01
  • 2018-01-16
  • 1970-01-01
  • 2010-09-11
  • 1970-01-01
  • 1970-01-01
  • 2021-10-11
  • 1970-01-01
  • 2013-06-06
相关资源
最近更新 更多