Search code examples
linuxparallel-processingpython-3.6raspberry-pi3

running multiple cmdline commands or files simultaneously in Raspberry pi through terminal


I have created file one which runs a flask server, starts the Alexa sample app and another is a cmdline command which runs port forwarding server.

which are:

led.py, sudo bash startsampleapp.sh, and the command is: autossh -M 0 -R 80:localhost:8000 serveo.net

So I want to run all these three from one file I tried using subprocess, Multiprocessing and os but didn't seem to work it doesn't go ahead of led.py. And this 3 should run simultaneously because to start Alexa I need to run Alexa sample app by this command: "sudo bash startsampleapp.sh" and when we ask Alexa to do something serveo.net will get the request and it will forward it to led.py(flask server).so Please help me regarding this.

I have tried creating a bash file like this:

#!usr/bin/bash

python led.py &
sudo bash startsampleapp.sh &
autossh -M 0 -R serveo.serveo.net:localhost:8000 serveo.net

It should start them in the parallel process but don't work.


Solution

  • The solution I found was opening 3 terminal and running that 3 things respectively.

    I create a bash file main.sh which contained:

    #!/bin/bash
    
    lxterminal -e python led.py &
    lxterminal -e autossh -M 0 -R serveo.serveo.net:80:localhost:8000 serveo.net &
    lxterminal -e sudo bash startsampleapp.sh
    

    Thanks all.

    Killing them can be done through getting the process ID and using sudo killall -9 ID command.