views:

96

answers:

3

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

A: 

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.

Ryan M
Can you expand please on compiling a statically linked perl executable? it may be my next problem after doing the chroot and passing the parameters like I want.
Carmageddon
Ok well since this works and I received no further replies, will mark as the answer.Basically the full answer is:chroot /mount-point /path/to/script "$var1" "$var2"
Carmageddon
If the $var1 and $var2 have any spaces or shell characters in them, you'd have to quote them in order to get them passed through intact.Re:static linking, you should run "ldd /path/to/your/perl" and see which libraries it needs. You can then copy these into the chroot area, along with the perl executable itself. If for some reason you don't want to copy these libraries in, you would need to rebuild Perl statically. The instructions on how to do so are in the INSTALL file included with the Perl source distro - the Configure option is -Uusedl, or you can set it in interactive configure.
Ryan M
A: 

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

Patkos Csaba
A: 

Both list concatenation and extension is available:

mylist = [1, 2] mylist + [5, 6] # concatenation [1,2,5,6]

mylist.extend([7, 8]) # extension print mylist [1,2,7,8]

mylist += [9, 10] # extension print mylist [1,2,7,8,9,10]

Jason Mock