Home > Software engineering >  Need to parallel run a video on multiple hosts BASH
Need to parallel run a video on multiple hosts BASH

Time:03-11

So I have a for loop where

  for HOST in $HOST_LOOP
   do
     ssh $HOST ... play video ... &
  done
  wait

I wanted to play the video on those hosts at the same time, that's what the & is for and the wait is for the script to keep running. But when I try to exit the bashscript, the processes still run on the background and the video keeps playing. I want to kill the processes, and I know that an individual host kills the video by ssh $Host pkill ffplay

So how can I kill these processes? The thing really throwing me off is this wait because it has essentially nothing to wait for, and it's becoming an infinite loop...

CodePudding user response:

how can I kill these processes?

for HOST in $HOST_LOOP; do
   ssh $HOST 'kill ...the_process_that_plays_the_video'
done

The quick and dirty solution is to run ssh -tt, that will forward signals to process runnin gon the other side.

CodePudding user response:

GNU Parallel had exactly the same problem.

It was solved by making a wrapper, that checked if the ssh connection was still there and if not: killed the local job. https://www.gnu.org/software/parallel/parallel_design.html#the-remote-system-wrapper

So maybe you can do:

# GNU Parallel wants hosts as: "host,host,host" not as "host host host"
hosts=$(echo "$HOST_LOOP" | perl -pe 's/ /,/g')
parallel -j0 -S"$hosts" --nonall play video

If this does not kill the job, try changing --termseq.

  • Related