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

发布于 2024-09-12 01:08:59 字数 367 浏览 4 评论 0原文

我想做这样的事情:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多情癖 2024-09-19 01:08:59

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.

沉鱼一梦 2024-09-19 01:08:59

或者您可以使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文