linux - Bash:从 chroot 和切换用户中执行命令

标签 linux bash unix chroot

我正在编写一个应该执行此操作的脚本...

chroot /chroot_dir/ su -
./startup.sh (This should run within the su environment)

我试过这种方法:

chroot /chroot_dir /bin/bash -c " su -; ./startup.sh"

这会尝试执行用户切换和脚本作为 bash 的字符串命令...不管它做了什么,它会在之后“停止”吗 “su -” 并且不执行脚本。 但是,一旦我离开“su -”环境,它就会尝试运行 startup.sh,但当然找不到。

基本上我需要嵌套要在“su -”环境中运行的“startup.sh”...

最佳答案

尝试

chroot /chroot_dir /bin/bash -c "su - -c ./startup.sh"

关于linux - Bash:从 chroot 和切换用户中执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8157931/

相关文章:

linux - bash:如何将文件 `cat` 之后的所有变量名替换为它们的值?

linux - 使用 xargs 删除目录

ruby - gosu 中的/usr/local/lib/ruby/gems/2.2.0/gems/gosu-0.10.4/lib/gosu/patches.rb :37:in `initialize' : Cannot open file ./media/image.jpg (运行时错误)

bash脚本重命名多个文件

linux - bash 中的 xmalloc 错误

linux - 检查目录是否不存在

c++ - 需要当前进程的 PID,getpid() 返回 -1

linux - 如何通过管道查找结果来解压缩?

linux - 如何在带双引号的ssh命令中处理单引号

linux - 在日志文件中计算时间