0

I have a shell script in a Unix environment, which itself calls other scripts (which they call other scripts), that I want to call from Windows using the task scheduler. You can imagine something like this:

myMainScript.sh          (in /myFolder/myOtherFolder)

Inside this, I make calls like:

#!/bin/bash
cd /myFolder/myOtherFolder       <-- this is to provide the context
cd otherSubFolder                <-- entering a subfolder
myOtherScript.sh                 <-- calling script in subfolder

Please note that myOtherScript.sh will also call other scripts, inside the same subfolder, which may eventually call other scripts and I can't modify those since they are "official" scripts I have no rights on.

When I run this script from a Shell console, everything works fine. When I run this script from plink, it raises me an error on the first command:

myOtherScript.sh: command not found

I hence tried to provide the absolute path, and instead of calling

myOtherScript.sh

... I call

/myFolder/myOtherFolder/otherSubFolder/myOtherScript.sh

In this case, the script is found and run, but then I have the same issue with the scripts which are called inside myOtherScript.sh (on which I have no modification rights).

I have also tried to put all the content of myMainScript.sh inside pushd + popd (providing the context /myFolder/myOtherFolder), but still no luck.

Can anyone lead me through the right direction?

P.s. just in case it helps, this is the way I call the script using plink (the call works, as I can read the logs of the command prompt showing that it's logged to the Unix environment):

"R:\tools\plink.exe" user@server-pw myPassword -sh -x "/myFolder/myOtherFolder/myMainScript.sh"
Matteo NNZ
  • 11,930
  • 12
  • 52
  • 89
  • Have your main script `cd` in its own directory before calling the other scripts that rely on a specific working directory? – Aaron Aug 28 '18 at 08:50
  • @Aaron yes, it's the very first command I launch. – Matteo NNZ Aug 28 '18 at 08:53
  • @MatteoNNZ Have you got `.` in your `$PATH`? Have you tried `./myOtherScript.sh`? – Biffen Aug 28 '18 at 08:55
  • Might be worth adding your main script to your question. – Aaron Aug 28 '18 at 08:58
  • @Biffen that worked, I just needed to add the . in front of the path! If you write it as an answer, I'll accept it. Thanks a lot! – Matteo NNZ Aug 28 '18 at 09:11
  • 1
    As an aside, the first `cd` doesn't do anything which introduces a "context". Switching to another directory immediately erases whatever "context" you were hoping for. – tripleee Aug 28 '18 at 10:07

0 Answers0