2

I want to run multiple Python scripts from shell. I used pythonDim.sh script to do the same.

#!/usr/bin/python
/home/path_to_script/dimAO.py
/home/path_to_script/dimA1.py
/home/path_to_script/dimA2.py
/home/path_to_script/dimA3.py

But it's not working. How to write the shell script?

5
  • 1
    That shebang is wrong; although the script may run Python scripts, it can't itself be executed as Python. Commented Mar 5, 2018 at 8:03
  • 2
    use #!/usr/bin/env bash to run it via a bash shell stackoverflow.com/questions/10376206/… or any other shebang depending on the shell you want to use Commented Mar 5, 2018 at 8:04
  • 2
    As mentioned above - change the header to bash and start each line by calling python, for example: python /home/path_to_script/dimAO.py Commented Mar 5, 2018 at 8:07
  • I want to run multiple Python scripts from shell - but your #! line says python, not a shell. Commented Mar 5, 2018 at 8:11
  • is it necessary to add header in python script dimA0.py. and is it necessary to make scripts executable? Commented Mar 5, 2018 at 8:18

1 Answer 1

7

To run sequentially:

#!/bin/bash
/home/path_to_script/dimAO.py
/home/path_to_script/dimA1.py
/home/path_to_script/dimA2.py
/home/path_to_script/dimA3.py

To run them all in parallel:

#!/bin/bash
/home/path_to_script/dimAO.py &
/home/path_to_script/dimA1.py &
/home/path_to_script/dimA2.py &
/home/path_to_script/dimA3.py &

Use redirection (> or >>) to redirect stdout and stderr, as desired.

Sign up to request clarification or add additional context in comments.

1 Comment

he should call every python script using python <path to python file> and to run in // I would recommend to add nohup in order to avoid that by closing your shell it kills all the processes!!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.