LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-01-2013, 04:52 AM   #1
blackray1
LQ Newbie
 
Registered: May 2011
Posts: 1

Rep: Reputation: 0
Unable to run another command from within shell script, when run from home directory


Hi All,

I am tryin to install an HP tool, HP OV from a script, to automate installation.

I am using the below command in shell script called ov_exec.sh

"source /tmp/LIN/oainstall.sh -i -a -precheckonly"

The install package is located in /tmp/LIN/oainstall.sh
oainstall.sh is the main script which calls upon subscripts based on OS and architechture.

The issue I am facing is one of the subscript does not execute as it is not found, if oainstall.sh is executed form another script, located in directory other than where the oainstall.sh package is located.

I tried giving absolute path to oainstall.sh in my script, still the subscript cannet be called upon, when this script is run from my home directory.
But when the script is run from /tmp/LIN where oainstall packages are located, it executes fine.
 
Old 07-01-2013, 06:19 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Very likely the script uses relative paths to files it requires.

It would help to know what the error message is.
 
Old 07-01-2013, 07:42 AM   #3
eahmedshendy
LQ Newbie
 
Registered: Jun 2013
Posts: 5

Rep: Reputation: Disabled
Hi blackray1,

Try replacing this line

Code:
source /tmp/LIN/oainstall.sh -i -a -precheckonly
with

Code:
oldPath=$PWD
linPath="/tmp/LIN/"
cd $linPath
source oainstall.sh -i -a -precheckonly
// Also execute whatever you want to do and related to this directory
cd $oldPath
// Then continue your progress

Last edited by eahmedshendy; 07-01-2013 at 10:49 AM. Reason: Correcting code.
 
Old 07-01-2013, 07:47 AM   #4
eahmedshendy
LQ Newbie
 
Registered: Jun 2013
Posts: 5

Rep: Reputation: Disabled
Code:
oldPath=$PWD  Here you save your current directory address in a variable
linPath="/tmp/LIN/"
cd $linPath   Change current working directory to /tmp/LIN/
source oainstall.sh -i -a -precheckonly   Now read/execute your script safely  
cd $oldPath  Return back to your current working directory

Last edited by eahmedshendy; 07-01-2013 at 10:53 AM. Reason: Correcting code.
 
Old 07-01-2013, 10:23 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
You wouldn't us a variable to hold the cd command though. Drop the "currentPath=" part (along with the quotes).

One problem using "source" is that it executes in the same context as the current shell, so you have to know what variables that script defines - because they will remain after the script is completed. That is the advantage of doing:

Code:
...
(cd /tmp/LIN/; oainstall.sh -i -a -precheckonly
...
This way a new subprocess is spawned with its own "working directory".
 
Old 07-01-2013, 10:37 AM   #6
eahmedshendy
LQ Newbie
 
Registered: Jun 2013
Posts: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
You wouldn't us a variable to hold the cd command though. Drop the "currentPath=" part (along with the quotes).

Code:
...
(cd /tmp/LIN/; oainstall.sh -i -a -precheckonly
...
Thank you for your advice.
I usually store all frequently used Linux command in variables.
 
Old 07-01-2013, 10:39 AM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Storing them there is fine. Its just that they don't get executed.
 
Old 07-01-2013, 10:42 AM   #8
eahmedshendy
LQ Newbie
 
Registered: Jun 2013
Posts: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
Storing them there is fine. Its just that they don't get executed.
OH hhhh, I'm sorry
I wrote the code wrong

currentPath="cd /tmp/LIN/"
$currentPath

This will execute it, sorry
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cant add new users for home directory keep getting errors no matter wich script i run highrolla Linux - Newbie 12 04-08-2013 05:06 PM
[SOLVED] run a shelll script from another shell script in another directory raulab Linux - Newbie 12 02-22-2011 06:18 PM
[SOLVED] Ran rm -rf on Home Directory unable to run commands as Root Nathan Spencer SUSE / openSUSE 4 06-13-2010 04:18 AM
[SOLVED] Script to open all subdirectories of a single directory and then run a command (help) Euler2 Linux - Newbie 7 03-24-2010 11:16 PM
How do I run a command in script from a particular directory? davee Linux - Newbie 1 08-07-2003 04:22 AM


All times are GMT -5. The time now is 10:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration