繁体   English   中英

如何以其他用户身份运行Linux命令列表

[英]How to run list of linux commands as different user

我必须以与当前登录用户不同的用户身份来执行命令列表。我尝试了以下脚本,它可以正常工作,但捆绑安装卡住了,没有出来。

sudo -u maneesh bash -c : && RUNAS="sudo -u maneesh"
$RUNAS bash<<_
cd /opt/maneesh/

unicorn_config="/opt/maneesh/config/unicorn.rb"

bundle install

bundle exec unicorn_rails -D -p 9001  -c $unicorn_config

_

任何帮助将不胜感激

为了以其他用户身份运行命令,您只需列出带有逗号的命令并以bash模式运行它们:

sudo -u maneesh bash -c 'cd /opt/maneesh/; unicorn_config="/opt/maneesh/config/unicorn.rb"; bundle install; bundle exec unicorn_rails -D -p 9001  -c $unicorn_config'

或者您可以简单地编写一个shell脚本:

list.sh (或其他名称):

cd /opt/maneesh/
unicorn_config="/opt/maneesh/config/unicorn.rb"
bundle install
bundle exec unicorn_rails -D -p 9001  -c $unicorn_config

并以另一个用户身份运行它:

sudo -u maneesh bash list.sh

我认为您的脚本可能在仅指定用户具有访问权限的cd /opt/maneesh上失败。 您可以通过更改访问权限来解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM