Reputation: 5204
I currently run a bunch of scripts in python and shell scripts in a server.
I am running them using GNU screen so that they can run in parallel.
counter=0
while read -r word; do
counter=$(( counter + 1))
screen -dmS $counter sh -c "python3 script1.py $word;exec bash"
done </home/user/Documents/wordlist.txt
counter=$(( counter + 1))
screen -dmS $counter sh -c "python3 script2.py;exec bash"
counter=$(( counter + 1))
screen -dmS $counter sh -c "python3 script3.py;exec bash"
this word list is 5 words long so it creates 5 processes. then there are 2 more processes after that for a total of 7 processes. each screen is named screen 1-7 based on the counter.
How do I get each screen process to create an environment number and so that it can remember what process number it was, based on the counter, so that when it ends I can use it for something else after that.
So that if I was in the screen number 6 I could type out $PROCESSNUMBER to recall that this was number 6. Preferably, I could run the same command in each screen.
Upvotes: 0
Views: 59
Reputation: 123750
You're running a shell command there, so just export a variable:
screen -dmS $counter sh -c "export PROCESSNUMBER=$counter; python3 script3.py;exec bash"
Upvotes: 1