How to run unix commands in a new shell inside a shell script? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How to run unix commands in a new shell inside a shell script?

Shell Programming and Scripting


Tags
unix commands

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-03-2006
hkapil hkapil is offline
Registered User
 
Join Date: Sep 2005
Last Activity: 4 January 2006, 5:58 AM EST
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 01-03-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 30 July 2014, 10:25 PM EDT
Location: Ashburn, Virginia
Posts: 9,897
Thanks: 58
Thanked 415 Times in 249 Posts
I would go with:

/usr/sbin/chroot /safedir/rdns /bin/sh -c "cd /opt/iws61/https-rdns ; ./stop ; ./start"
Sponsored Links
    #3  
Old 01-04-2006
hkapil hkapil is offline
Registered User
 
Join Date: Sep 2005
Last Activity: 4 January 2006, 5:58 AM EST
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks it worked

Thanks Prederabo !!!!,
It worked for me...
The remaining commands ran in the newly created shell..
Thanks again ...
hkapil
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 03:24 AM.