Hi ,
I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell.
So scenario is that
- I need to have one shell script which is ran as a part of crontab
- in this shell script I need to do a "chroot" to some particular directory .
- After chroot I need to run some unix command.
Here is the script
*****************************************
#!/usr/bin/ksh
cd /safedir/rdns/opt/MKDownload
#java MKProcessor
Val=`diff /safedir/rdns/opt/MKDownload/sun.csv
/safedir/rdns/opt/RDNS1.1/WEB-INF/lib/sun.csv |wc
-l`
if [ $Val -gt 0 ];
then
(
# `mv /safedir/rdns/opt/RDNS1.1/WEB-INF/lib/sun.csv
/safedir/rdns/opt/RDNS1.1/WEB-INF/lib/sun.csv.bak`
# `cp /safedir/rdns/opt/MKDownload/sun.csv
/safedir/rdns/opt/RDNS1.1/WEB-INF/lib`
/usr/sbin/chroot /safedir/rdns /bin/sh ------------------1
echo \`pwd\` -------------------------------------- 2
cd /opt/iws61/https-rdns/
./stop
./start
)
fi
*****************************************
So as apparent from script , after chrooting in line 1 , it creates a new shell and the execution of this script suspends there.
As soon as I 'exit' the shell the remaining commands from line 2 onwards execute in current shell and I get error. But as per my requirement the remaining commands need to run from chrooted directory only i.e new shell created as a result of command at line 1.
Please provide any insight how to solve this ?
Thanks in advance
HKapil