1

I am working with Datastage which uses a Command Executable Stage to call a parameterized Shell Script. This question is not about datastage. it's about how to call the shell script.

Right now, The logic of datastage is to call the script three times using different parameters for each time it's called. For example:

Call script.sh file1.txt -> Wait for `exit 0` -> call script.sh file2.txt -> Wait for `exit 0` -> call script.sh file3.txt -> wait for `exit 0`

The command for calling the script looks like this:

/var/opt/scripts/Project/script.sh file1.txt

what I'm hoping to do is call all three shell scripts at the same time. How can I call the script in a way that allows me to do it two more times simultaneously?

Thanks.

UPDATE 1

I want to appreciate the incoming on this question. One thing to clear up, is that I cannot call all three script.sh commands from the same call. This is called from three independent and identical spots in the app.

Thanks

Community
  • 1
  • 1
arcee123
  • 101
  • 9
  • 41
  • 118
  • You are probably looking for the wait command http://man7.org/linux/man-pages/man1/wait.1p.html This would allow you to gather the process IDs from your various commands and then wait for them all to finish. – Gem Taylor May 20 '19 at 13:28
  • Your question is absolutely about datastage, and how you call processes from it. Unless you want to write simple wrapper script in which you write `E=/var/opt/scripts/Project/script.sh; $E & $E & $E & wait;` – William Pursell May 20 '19 at 13:32
  • Did you try `/var/opt/scripts/Project/script.sh file1.txt &` ? When you start a background process `&` three times, it will start 3 times. You should take core for how you handle temporary files, stdout and scripts still running after closing the app. – Walter A May 20 '19 at 15:23
  • 1. Do you have to account for a possibility that a script run fails and exits with a non-0 value? 2. Does the last script call have a file name argument from which it can be determined that it's the last run (like the `3` in `file3.txt`)? 3. Can you modify `script.sh`? – Armali May 21 '19 at 10:53

1 Answers1

2

GNU parallel (https://www.gnu.org/software/parallel/) is a shell tool for executing jobs in parallel.

For your example something like that should work:

seq -w 1 3 | parallel ./script.sh file{}.txt

Please look at parallel's man page and the info on its gnu.org home page.

zzeroo
  • 5,466
  • 4
  • 33
  • 49