简体   繁体   English

运行带有 su 错误的 shell 脚本

[英]Run shell script with su errors

I have a script that is run by root and looks like this我有一个由 root 运行的脚本,看起来像这样

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

Everything works fine until the last su command.一切正常,直到最后一个su命令。 It gives me the error它给了我错误

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

How can I make the user guest execute the script.sh using su ?如何让用户guest使用su执行script.sh

From man su :来自man su

SYNOPSIS 概要
su [options] [-] [user [argument...]] su [选项] [-] [用户[参数...]]

You changed the order of the parameters.您更改了参数的顺序。 Try this way:试试这个方法:

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

Note the quotes " before the start and after the end of the command. Moreover, I suggest you to use absolute path also for sh .注意命令开始之前和结束之后的引号" 。此外,我建议您也对sh使用绝对路径。

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

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