When you run chroot
without telling it what to do, it will try to start chrooted interactive shell session. So your script would "pause" at that point and when you are done with that interactive shell session, it continues out of chroot again.
One of the quick and dirt options would be to abuse here-document, like this:
chroot /home/mayank/chroot/codebase /bin/bash <<"EOT"
cd /tmp/so
ls -l
echo $$
EOT
Which takes all lines up to EOT
and feeds them into bash
started through chroot
. Those double quotes around "EOT"
should ensure bash passes the content not trying to expand variables and such. Hence that echo $$
should be PID of the inner chrooted bash
.
chroot /home/whatever "COMMAND"
chroot can have command – PonderCOMMAND
can execute a script in the chroot. – Wershba