简体   繁体   English

Bash:Chroot命令传递2个字符串参数或更好地运行一系列命令

[英]Bash: Chroot command passing 2 string parameters or better run a series of commands

I would like to do something like this: 我想做这样的事情:

chroot /mount-point /path/to/script $var1 $var 2

Will this work? 这样行吗? Will the chrooted Perl script be passed on these 2 parameters? chrooted Perl脚本是否将通过这两个参数传递? If not, how to do this? 如果没有,该怎么做?

Otherwise, is there any way to simply do chroot in the script, and then start doing commands such as 否则,有什么方法可以简单地在脚本中执行chroot ,然后开始执行以下命令:

perl script.pl $var1 $var2 etc?

As I understand it, simply writing them sequentially in bash will only get them executed after chroot is finished, and control is returned back to where I don't have perl installed (its a ramdisk running from PXE). 据我了解,简单地在bash顺序写入它们只会在chroot完成后才使它们执行,并且控制权返回到我未安装perl (它是从PXE运行的ramdisk)。

Chroot should handle this just fine. Chroot应该可以解决这个问题。 Just make sure that your perl script can find a Perl interpreter from the chroot context, that the Perl executable can find the shared libraries it needs, and that your variables, if they contain paths, have paths relative to the new root, not the old. 只需确保您的perl脚本可以从chroot上下文中找到Perl解释器,确保Perl可执行文件可以找到所需的共享库,并且您的变量(如果包含路径)具有相对于新根目录(而非旧目录)的路径。 You may want to compile a statically-linked perl executable, if that's easier for you than making copies of the required shared libraries in the chroot. 如果您比在chroot中复制所需的共享库更容易,则可能需要编译静态链接的perl可执行文件。

Or you can use Expect, which is a scripting language for interacting with input/output. 或者,您可以使用Expect,这是一种用于与输入/输出进行交互的脚本语言。 http://en.wikipedia.org/wiki/Expect http://en.wikipedia.org/wiki/期望

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

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