I'm trying to start a process on multiple VMs using GitHub Actions. However, the command doesn't complete (as it needs to continue running) so my for loop just kind of hangs.
What I need, is a way to inspect the command's log output (which is in a known file) and then continue the loop whenever a specific sentence appears in the log file.
This is a minimal example of what I currently have:
#! /bin/bash
VMS=("10.10.789.001" "10.10.789.002" "10.10.789.003")
for VM in "${!VMS[@]}"; do
command.sh "$VM"
done
command.sh:
#! /bin/bash
vmip=$1
ssh user@"$vmip" -T "myprogram -flag &> output.log"
This works in a sense that the connection is made, myprogram
is started and its output redirected to output.log
. However, since the myprogram
continues running (as is intended), the for
loop never reaches done
.
I've tried setting a timeout
like this:
#! /bin/bash
VMS=("10.10.789.001" "10.10.789.002" "10.10.789.003")
for VM in "${!VMS[@]}"; do
timeout 5m command.sh "$VM"
done
That however ends the whole script because it effectively throws an exit
after the timeout is reached, and that still doesn't continue the for
loop.
I know that myprogram
will write setup complete
to the output.log
file, so I could check for that by doing something like:
#! /bin/bash
cat vault.log | grep "setup complete"
if [ $? = 0 ]; then
<do something>
fi
If the condition above satisfies, the program has completed setting up and is now just running, which is what I want. However, I don't know what the <do something>
part needs to do, in order to ensure the original for
loop can continue.
Note I do not have access to the contents of the myprogram
program. It's simply an existing program which I need to run, not something I can alter myself.
ssh
command and then run a for loop which checks the logs. But then you will have all thessh
processes continously running, but from what I understand that is what you want even though the "setup part" is done.