I'm on a Mac computer accessing by ssh a linux machine to run simulations. I'm currently running multiple commands in parallel (I put them in background with &), when they finish I extract the files of interest then delete all commands output and redo it.
I wondered if it was possible to check using the PID if those tasks are finished in order to automatically extract the wanted files and launch one more time the exact same command. I'm posting a message here to know to get the PID of a command which is executed through a ssh -c, that is not done by me (as I'm in remote linux).
I tried the solutions shown in how-to-get-pid-of-just-started-process in order to get the PID, but neither $! nor ssh -c nor jobs -p give me the correct PID. I'm wondering if it doesn't work because I'm on remote access (the command appearing in htop is a ssh -c ...) or I'm just doing things poorly.
Here is my first bash script :
#!/bin/bash
./createFiles.sh $1 # create the needed $1 folders
for i in $(seq 1 $1)
do
cd $i
myCommand &
cd ..
done
When this one is finished I use :
#!/bin/bash
for i in $(seq 1 $1)
do
cd $i
cp output/file.txt ../file_$2_$i.txt # $2 is the number of the run
cd ..
done
./deleteFiles.sh $2 # delete the needed $1 folders to start anew
And then I loop 5 times those two. And I wanted to know if it's possible to loop automatically 5 times and not having me standing in front of my computer.
If any of you have any idea, it would be great :)
P.S: I hope it was clear, english is not my native language hihi
$$to get the PID from inside your script. You could also usepgrepto find the PID of a given process name from outside your script.pgrepexistence, thank you very much :)