Bash:Chroot 命令传递 2 个字符串参数或更好地运行一系列命令
我想做这样的事情:
chroot /mount-point /path/to/script $var1 $var 2
这可行吗? chrooted Perl 脚本会传递给这 2 个参数吗? 如果没有,该怎么做?
否则,有没有办法简单地在脚本中执行 chroot,然后开始执行诸如
perl script.pl $var1 $var2 etc?
据我所知,简单地在 bash 中按顺序编写它们只会得到它们chroot
完成后执行,控制权返回到我没有安装 perl
的地方(它是一个从 PXE 运行的 ramdisk)。
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?
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
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Chroot 应该可以很好地处理这个问题。只需确保您的 Perl 脚本可以从 chroot 上下文中找到 Perl 解释器,Perl 可执行文件可以找到它需要的共享库,并且您的变量(如果它们包含路径)具有相对于新根而不是旧根的路径。您可能想要编译静态链接的 perl 可执行文件,如果这比在 chroot 中制作所需共享库的副本更容易的话。
Chroot should handle this just fine. 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. 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.
或者您可以使用 Expect,它是一种用于与输入/输出交互的脚本语言。
http://en.wikipedia.org/wiki/Expect
Or you can use Expect, which is a scripting language for interacting with input/output.
http://en.wikipedia.org/wiki/Expect