The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
rlogin inside a c-shell script sumitgarg Shell Programming and Scripting 5 01-31-2008 08:27 PM
writing Enter key inside in shell script bishweshwar Shell Programming and Scripting 3 01-04-2008 08:45 AM
How to run an SQL script inside a shell stevefox Shell Programming and Scripting 1 06-15-2006 07:11 PM
ftp files inside a shell script matrix1067 Shell Programming and Scripting 5 02-07-2006 01:31 PM
Using tar inside a shell script kas7225 Shell Programming and Scripting 2 05-19-2005 08:06 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-03-2006
Registered User
 

Join Date: Sep 2005
Posts: 10
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-03-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,453
I would go with:

/usr/sbin/chroot /safedir/rdns /bin/sh -c "cd /opt/iws61/https-rdns ; ./stop ; ./start"
Reply With Quote
  #3 (permalink)  
Old 01-04-2006
Registered User
 

Join Date: Sep 2005
Posts: 10
Thanks it worked

Thanks Prederabo !!!!,
It worked for me...
The remaining commands ran in the newly created shell..
Thanks again ...
hkapil
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0