简体   繁体   中英

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? 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).

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.

Or you can use Expect, which is a scripting language for interacting with input/output. http://en.wikipedia.org/wiki/Expect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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