在脚本中使用sudo执行aws命令



我正在运行sudobash脚本,并尝试了下面,但使用aws cp得到下面的错误。我认为问题是脚本正在寻找config/root中并不存在。然而-E不是保留了原来的位置吗?是否有一个选项可以与aws cp一起使用来传递config的位置?谢谢。

sudo -E bash /path/to/.sh
- inside of this script is `aws cp`

误差

The config profile (name) could not be found

I have also tried `export` the name profile and `source` the path to the `config`

可以使用原用户:

sudo -u $SUDO_USER aws cp ...

您也可以使用source而不是bash来运行脚本——使用source将导致脚本在与您打开的终端窗口相同的shell中运行,这将保持相同的环境在一起(例如user) -尽管老实说,@Philippe答案是更好,更正确的。

最新更新