Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 11th, 2012, 10:59 AM
sujoydc sujoydc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 14 sujoydc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 41 m
Reputation Power: 0
Send a message via Yahoo to sujoydc
Calling another shell script with relative path problem

Hello,

I want to execute a file (runFile.sh) from a different directory.
Inside 'runFile.sh' (which is not my code so I can't change this file) first few lines are like this:

Code:
cd ../..
. env.sh 


So, when I try to call this file it is failing saying that 'env.sh' not found.
My Code:
Code:
#!/usr/bin/ksh
FOLDER_ID=19
/app/peter/Source/patch/$FOLDER_ID/runFile.sh >> spitOut.log
....


Then I changed code like this.

Code:
#!/usr/bin/ksh

BASE_LOC=/home/base
BASE_SOURCE_LOC=/app/peter/Source
FOLDER_ID=19

`cd $BASE_SOURCE_LOC/patch/$FOLDER_ID`
echo "Directory changed to:"`pwd`
./runFile.sh >> spitOut.log
`cd $BASE_LOC/files`
echo "Directory changed to:"`pwd`


When I run this file the cd command doesn't work.

How can I solve this problem?

Reply With Quote
  #2  
Old July 11th, 2012, 12:09 PM
safesurfdns safesurfdns is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 15 safesurfdns User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 56 m 55 sec
Reputation Power: 0
Quote:
Originally Posted by sujoydc
Hello,

I want to execute a file (runFile.sh) from a different directory.
Inside 'runFile.sh' (which is not my code so I can't change this file) first few lines are like this:

Code:
cd ../..
. env.sh 


So, when I try to call this file it is failing saying that 'env.sh' not found.
My Code:
Code:
#!/usr/bin/ksh
FOLDER_ID=19
/app/peter/Source/patch/$FOLDER_ID/runFile.sh >> spitOut.log
....


Then I changed code like this.

Code:
#!/usr/bin/ksh

BASE_LOC=/home/base
BASE_SOURCE_LOC=/app/peter/Source
FOLDER_ID=19

`cd $BASE_SOURCE_LOC/patch/$FOLDER_ID`
echo "Directory changed to:"`pwd`
./runFile.sh >> spitOut.log
`cd $BASE_LOC/files`
echo "Directory changed to:"`pwd`


When I run this file the cd command doesn't work.

How can I solve this problem?


This usually isn't a problem when you just use absolute paths to rather than using cd to change directories.

How are you executing this? through crontab?

Reply With Quote
  #3  
Old July 11th, 2012, 12:24 PM
sujoydc sujoydc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 14 sujoydc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 41 m
Reputation Power: 0
Send a message via Yahoo to sujoydc
I tried using full path to execute the script.
But inside that script it's doing cd and trying to load a file.
I am running my script from ksh shell manually (no corntab I guess).

If you see my original post, I had posted my first code and the second code.
Error messages:

1. First Code:
env.sh: cannot open [No such file or directory]

2. Second Code:
runFile.sh: not found [No such file or directory]

Reply With Quote
  #4  
Old July 11th, 2012, 12:45 PM
safesurfdns safesurfdns is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 15 safesurfdns User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 56 m 55 sec
Reputation Power: 0
Quote:
Originally Posted by sujoydc
I tried using full path to execute the script.
But inside that script it's doing cd and trying to load a file.
I am running my script from ksh shell manually (no corntab I guess).

If you see my original post, I had posted my first code and the second code.
Error messages:

1. First Code:
env.sh: cannot open [No such file or directory]

2. Second Code:
runFile.sh: not found [No such file or directory]


add an echo $FOLDER_ID to your script to see if your variable is getting screwed up somehow...

Also why do you have two variables for BASE_LOC and BASE_SOURCE_LOC?

Couldn't you simply do

BASE_LOC=/home/base/app/peter/source/patch/$FOLDER_ID ?

set that then do an echo $BASE_LOC
/bin/ls -l $BASE_LOC

does that work?

Reply With Quote
  #5  
Old July 11th, 2012, 01:00 PM
sujoydc sujoydc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 14 sujoydc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 41 m
Reputation Power: 0
Send a message via Yahoo to sujoydc
Thanks "safesurfdns" for helping me out.

Let me explain you the scenario here.

I have two separate types of scripts here.
1. You can say third party script in a separate location. I can't change their scripts nor the location ie. BASE_SOURCE_LOC.
2. My own script which is calling #1 and in another location. ie. BASE_LOC

Running #1 using direct path will never work as inside their code they are using relative path.
First couple of lines of their code:
Code:
cd ../..
. env.sh 


So, I somehow have to change to their location (BASE_SOURCE_LOC) to execute their script(#1) from my script (#2).

Please let me know if you need more info.

Reply With Quote
  #6  
Old July 11th, 2012, 07:33 PM
sujoydc sujoydc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 14 sujoydc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 41 m
Reputation Power: 0
Send a message via Yahoo to sujoydc
resolved the problem by implementing pushd and popd functions.
thanks guys...

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Calling another shell script with relative path problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap