Track and kill the PIDS

I have a script that conducts some SSH calls and I would like to capture the child info so that I can do a sleep and then a cleanup to make sure they do not stay out there as ghosts.

I was told I could do something like this...

#!/bin/sh
for m = job1, job2, job3
 
x=1
/lcl/tools/bin/sshPing.pl delphin
x=$?
if [ $x = '0' ]; then
/lcl/bin/ssh delphin "/lcl/apps/Tivoli/omnibus_procedure_scripts/delphin_fire.sh" &
fi
x=1
/lcl/tools/bin/sshPing.pl penribbon
x=$?
if [ $x = '0' ]; then
/lcl/bin/ssh penribbon "/lcl/apps/Tivoli/omnibus_procedure_scripts/penribbon_fire.sh" &
fi
x=1
/lcl/tools/bin/sshPing.pl blackracer
x=$?
if [ $x = '0' ]; then
/lcl/bin/ssh blackracer "/lcl/apps/Tivoli/omnibus_procedure_scripts/blackracer_fire.sh" &
fi
echo jobs
exit

But thats not working. I am not a really good at this yet.
I want to catch the PIDS or whatever I need so that after a sleep of say... 300 I could then tell the script to go kill all the PIDS that were started to make sure they finished.

Could somebody help me out here with it?
Thanks

---------- Post updated at 06:08 AM ---------- Previous update was at 05:05 AM ----------

I just need to find a way to have the script compile a list of all the PIDS created from doing the SSH calls so it can then go through at the end to check that they all ended and if not kill them.

Really need some help here please if anyone can.

Thanks!

You can terminate programs by their PID with

kill -9 $(pidof your_program)

here is a quick example that I use for stuff like this...

#!/bin/bash

ssh_fuction () {
  ssh $1 "my commands go here...." &
  return_code=$?
  sleep 300
  kill -9 $return_code
}

for servers in $somelist
do
  ssh_function $servers &
done

you can also add to the for loop a while loop so that you only run the command on x number of servers at time... etc...

Can you please explain what this coding exactly does.... ?

Can you please learn the basics of shell scripting?