Reputation: 5037
I have bash script that runs a long running process that prints a lot of stuff to stdout. I made the script print the process output only after it finished and only if it failed.
My problem is that some CI require some stdout prints every X minutes and the process sometimes take a lot more than those X minutes.
I'm trying to think of bash solution that would:
Here's is what I started writing:
run_process > output.txt 2>&1 & my_pid=$!
exited=0
while [ ${exited} -eq 0 ]
do
timeout wait 5s ${my_pid};exit_code=$?;exited=1
echo .
done
clearly, that doesn't work since timeout cannot get a series of commands. Do you have other solutions?
Upvotes: 0
Views: 24
Reputation: 6168
Try this:
run_process > output.txt 2>&1 & my_pid=$!
while ps -p $my_pid > /dev/null; do
echo -n .
sleep 5
done
Get exit value from wait
:
wait $mypid
echo $?
Upvotes: 0