#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    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?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    15
    Rep Power
    0
    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?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    14
    Rep Power
    0
    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]
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    15
    Rep Power
    0
    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?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    14
    Rep Power
    0
    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.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    14
    Rep Power
    0
    resolved the problem by implementing pushd and popd functions.
    thanks guys...

IMN logo majestic logo threadwatch logo seochat tools logo