gpt4 book ai didi

linux - Bash 需要 root 用户。在同一个脚本中还是单独的脚本中?

转载 作者:太空宇宙 更新时间:2023-11-04 03:32:55 25 4
gpt4 key购买 nike

在这里编写新手脚本,处理需要 root、用户、root 的 bash 脚本。我在用户终端中 su 之后运行它。最初尝试:

su -c - "$USER" "export PKGDEST=/tmp/test/AUR/" 
su -c - "$USER" "pacaur --noconfirm --noedit -cm" "$(< /tmp/test/aur)"

无论如何,第二行都会崩溃,不同的错误,取决于报价组合、位置。运行后续代码,第二行在读取文件/tmp/test/aur::no Targets specified (use -h for help) 后产生以下错误。

pacaur --noconfirm --noedit -cm "$(< /tmp/test/aur)"

以用户身份启动脚本时运行良好。我的第一选择是让这个方法正常工作。

Google等..说bash中的root、user、root不好,所以尝试将其分成3部分:

1) 第一个脚本以 root 身份运行。问题集中在这里,无法启动第二个。

2) 第二个脚本以用户身份运行,以 root 身份启动第三个脚本: sudo/bin/bash "$L"/copyaur.sh

3) 第三个脚本 copyaur.sh 启动、运行,移动一些包,但由于调用新 shell 而未显示在终端中。

下面是在测试期间在用户终端中作为 su 运行的。更喜欢使用 $USER var 作为 whoami 报告 root而 echo $USER 报告用户名。切换su后,然后su - $USER,ls in ~显示我的主页内容。

[dom@arch testing]$ echo $USER

dom
[root@arch testing]# echo $USER

dom
[root@arch testing]# pwd
/home/dom/scripts/testing


su - $USER home/$USER/scripts/testing/buildaur.sh - No such file or directory
su --login $USER home/$USER/scripts/testing/buildaur.sh - No such file or directory
su - $USER home/dom/scripts/testing/buildaur.sh - No such file or directory
su - "$USER" home/dom/scripts/testing/buildaur.sh - No such file or directory
su - "$USER" ./buildaur.sh - No such file or directory
su - dom ./buildaur.sh - No such file or directory

su - dom ~/scripts/testing/buildaur.sh - Permission denied
su - $USER ~/scripts/testing/buildaur.sh - Permission denied
su --login dom ~/scripts/testing/buildaur.sh - Permission denied

su - dom /home/dom/scripts/testing/buildaur.sh - Runs as user, expected
su --login dom /home/dom/scripts/testing/buildaur.sh - Runs as user, expected
su - dom /home/$USER/scripts/testing/buildaur.sh - Runs as user, expected

最佳答案

/tmp/test/AUR/tmp/test/aur 是不同的文件。大多数文件系统都区分大小写。

关于linux - Bash 需要 root 用户。在同一个脚本中还是单独的脚本中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32605781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com