首页 > 解决方案 > 运行带有 su 错误的 shell 脚本

问题描述

我有一个由 root 运行的脚本,看起来像这样

curl -O some stuff
mv it to user guest directory
su - guest -c sh /home/guest/script.sh

一切正常,直到最后一个su命令。它给了我错误

sh: cannot set terminal process group (-1): inappropriate ioctl for device
sh: no job control in this shell

如何让用户guest执行script.shusing su

标签: bash

解决方案


来自man su

概要
su [选项] [-] [用户 [参数...]]

您更改了参数的顺序。试试这个方法:

su -c "/path/to/sh /home/guest/script.sh" - guest

"注意命令开始之前和结束之后的引号。此外,我建议您也为sh.


推荐阅读