Sponsored Content
Top Forums Shell Programming and Scripting How to run unix commands in a new shell inside a shell script? Post 94681 by hkapil on Tuesday 3rd of January 2006 04:30:27 AM
Old 01-03-2006
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run an SQL script inside a shell

How do I create a K Shell which would silently (without user input) logon to Oracle and run an SQL script? Any help will be greatly appreciated. Steve (1 Reply)
Discussion started by: stevefox
1 Replies

2. Shell Programming and Scripting

shell script to run a few commands help!

Hi friends this is first post i am very new to shell scripting so i require your expertise to do the following thank u I need to write a shell script which will run the following commands pg_dump bank > backup(Enter) Wait for bash prompt to appear coz it indicates that the command is... (23 Replies)
Discussion started by: perk_bud
23 Replies

3. Shell Programming and Scripting

How to use ftp commands inside shell script? Help please

Dears, I'm new in shell scripting and i need your help, i would like to know how can i create a script to ftp to a certain unix/linux machine/server IP address and get a file for example without user intervention? How can i force the script to use a certain username and password to access this... (4 Replies)
Discussion started by: Dendany83
4 Replies

4. Shell Programming and Scripting

Unix commands failing inside the shell script

When my script deals with large input files like 22Gb or 18 GB the basic commands like sort or join fails when run from inside the shell scripts. Can there be any specific reason for this? For e.g. sort -u -t "," -k1,1 a.csv > a.csv.uniq" sort -u -t "," -k1,1 b.csv > b.csv.uniq" The... (3 Replies)
Discussion started by: esha
3 Replies

5. Shell Programming and Scripting

shell script to run commands in different terminals

hi, how to write shell script that runs different commands(like:ls,ps,ls-l) in differnt terminals(each command should run in different terminal). my main motive is to run different 'c' program exe's available in different locations in different terminals. thanks sai (2 Replies)
Discussion started by: saidopdf
2 Replies

6. UNIX for Dummies Questions & Answers

Commands to run from shell script

Hi script> isumid 98765432 if i give above command in cmd prompt it is running the same thing if i give inside the shell script it is not working below is the code #!/bin/bash isumid 98765432 please give me a solution (16 Replies)
Discussion started by: Ramrangasamy
16 Replies

7. Shell Programming and Scripting

Run .exe inside shell script

I have to run some shell scripts in Windows using Cygwin. I am able to achieve that using %BASH% --login -i "/cygdrive/d/script.sh" , where %BASH% is an environment variable in Windows set to C:\cygwin\bin\bash.exe. I have a created a Cygwin environment variable $EXE_PATH =... (3 Replies)
Discussion started by: HemanthJayasimh
3 Replies

8. Shell Programming and Scripting

RMAN commands inside crontab shell script

Hello I'm trying to write simple script to delete archive logs for RMAN, unfortunately it's not working, I tried two way to do that: #!/bin/ksh echo "Start ....." rman target=/ << EOF RUN { delete force noprompt archivelog until time 'sysdate-10'; } EXIT; EOF echo "END ..." echo... (6 Replies)
Discussion started by: samer.odeh
6 Replies

9. Shell Programming and Scripting

How to run scripts parallely inside shell script?

Hi , I have 4 scripts example script1,script2,script3,script4 . I have to run script1,script2 and script3 parallely since this 3 scripts dont have dependencies . Once script1,script2 and script3 got completed successfully , I have to trigger script4. Can someone help me on this how to... (10 Replies)
Discussion started by: vinothsekark
10 Replies

10. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies
lib::abs(3pm)						User Contributed Perl Documentation					     lib::abs(3pm)

NAME
lib::abs - "lib" that makes relative path absolute to caller. SYNOPSIS
Simple use like "use lib ...": use lib::abs qw(./mylibs1 ../mylibs2); use lib::abs 'mylibs'; Extended syntax (glob) use lib::abs 'modules/*/lib'; There are also may be used helper function from lib::abs (see example/ex4): use lib::abs; # ... my $path = lib::abs::path('../path/relative/to/me'); # returns absolute path DESCRIPTION
The main reason of this library is transformate relative paths to absolute at the "BEGIN" stage, and push transformed to @INC. Relative path basis is not the current working directory, but the location of file, where the statement is (caller file). When using common "lib", relative paths stays relative to curernt working directory, # For ex: # script: /opt/scripts/my.pl use lib::abs '../lib'; # We run `/opt/scripts/my.pl` having cwd /home/mons # The @INC will contain '/opt/lib'; # We run `./my.pl` having cwd /opt # The @INC will contain '/opt/lib'; # We run `../my.pl` having cwd /opt/lib # The @INC will contain '/opt/lib'; Also this module is useful when writing tests, when you want to load strictly the module from ../lib, respecting the test file. # t/00-test.t use lib::abs '../lib'; Also this is useful, when you running under "mod_perl", use something like "Apache::StatINC", and your application may change working directory. So in case of chdir "StatINC" fails to reload module if the @INC contain relative paths. RATIONALE
Q: We already have "FindBin" and "lib", why we need this module? A: There are several reasons: 1) "FindBin" could find path incorrectly under "mod_perl" 2) "FindBin" works relatively to executed binary instead of relatively to caller 3) Perl is linguistic language, and `use lib::abs "..."' semantically more clear and looks more beautiful than `use FindBin; use lib "$FindBin::Bin/../lib";' 4) "FindBin" b<will> work incorrectly, if will be called not from executed binary (see <http://github.com/Mons/lib-abs-vs-findbin> comparison for details) BUGS
None known COPYRIGHT &; LICENSE Copyright 2007-2010 Mons Anderson. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AUTHOR
Mons Anderson, "<mons@cpan.org>" CONTRIBUTORS
Oleg Kostyuk, "<cub@cpan.org>" perl v5.10.1 2010-11-16 lib::abs(3pm)
All times are GMT -4. The time now is 08:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy