I have a loop in a Bash shell script that repeatedly calls a Python script (here, "checkservice"), and exits when the Python script produces a particular output string:
while true; do
v=$(/usr/bin/checkservice /show | grep "process.*boot.*Applied")
if [ "$v" != "" ]; then
echo "Process found"
The same loop construct is used elsewhere, but with different commands (e.g. a "ps" to wait for another process to stop). The time_elapsed function displays the time since the start of the loop.
In most instances of this loop, it successfully displays the time until the correct pattern is printed out, then displays the "Process found" line and carries on with the rest of the script, displaying text as it goes. With this particular version, the time display starts incrementing, but around the time that the text condition is met, the display just hangs. The script itself carries on, it's just that there is no output. If I press a key (e.g. the space bar), the output stream suddenly comes back to life, displaying text from the last few passes through the loop, and all of the text that came after the loop.
I can't post the contents of the "checkservice" command (it's proprietary, and enormous), but I am asking what sort of thing I should be looking for to see why the output stops. I've tried it with a cut-down Python script, and it doesn't hang in the same way, so there must be something in the main code which causes this. The Python script is not interactive - it just takes its arguments, and produces data based on the particular arguments.
Alternatively, is there any way i can protect the shell script from this behaviour? I've tried redirecting the input to the Python code (e.g. by adding "echo |" in front of it, and by adding "</dev/null" after it). The code used to have the "checkservice" command running as a simple command with a grep after it, and the code would check the return code from the grep, but that hangs too.