0

I am running an Instagram bot using python and selenium. I use a bash script to run a python script with the accounts credentials(Username, password, hashtags, etc...) I run multiple Instagrams so I have made multiple copies of this file. Is there a way to put this in a single file that I can click on and run? To open multiple terminals running their assigned account?

I've already tried just to add them to one big file but the scripts wont run until the previous one finishes.

Also since I'm using selenium, trying multi threading in python is somewhat difficult but would not mind going that route if someone could point me to where I could start with that.

#!/bin/sh
cd PycharmProjects/InstaBot
python3 W.py
howie
  • 2,587
  • 3
  • 27
  • 43
Jesuscdev
  • 15
  • 3

2 Answers2

0

I highly recommend that everyone read about Bash Job Control.

Getting into multithreading is ridiculous overkill if your bottleneck has nothing to do with the CPU.

for script in PycharmProjects/InstaBot/*.py; do
  python3 "$script" &
done
jobs
vintnes
  • 2,014
  • 7
  • 16
0

Only one process in shell can run in foreground mode. So the command gets executed only when the previous completes. Adding "&" symbol at the end of the command line tells shell that the command should be executed in the background. This way the shell will start python and continue without waiting.

This will execute two instances simultaneously, but they will all output to the same terminal:

    #!/bin/sh
    cd PycharmProjects/InstaBot
    python3 W.py first_credentials &
    python3 W.py second_credentials &

You can use the same technique to start a new terminal process for each python script:

    #!/bin/sh
    cd PycharmProjects/InstaBot
    gnome-terminal   -e "python3 W.py first_credentials"  &
    gnome-terminal   -e "python3 W.py second_credentials" &
JKW
  • 41
  • 4