|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to run unix commands in a new shell inside a shell script?
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 |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
I would go with:
/usr/sbin/chroot /safedir/rdns /bin/sh -c "cd /opt/iws61/https-rdns ; ./stop ; ./start" |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks it worked
Thanks Prederabo !!!!,
It worked for me... The remaining commands ran in the newly created shell.. Thanks again ... hkapil |
| Sponsored Links | ||
|
![]() |
| Tags |
| unix commands |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help embedding Unix commands in a shell script | rogers42 | Shell Programming and Scripting | 4 | 09-28-2011 01:47 PM |
| Error while using sqlplus command inside 'if' condition in an unix shell script | Shri123 | Shell Programming and Scripting | 6 | 11-01-2010 10:09 PM |
| to create a phone book using shell script and unix commands | monster11209 | Shell Programming and Scripting | 1 | 09-22-2009 10:44 AM |
| Unix commands failing inside the shell script | esha | Shell Programming and Scripting | 3 | 06-02-2009 08:32 AM |
| How to use ftp commands inside shell script? Help please | Dendany83 | Shell Programming and Scripting | 4 | 04-06-2009 12:58 PM |
|
|