So this is probably a simple question, but I don't really like the bash programmer, and I could not figure it out.
We have a closed source program that calls a subroutine that runs before it exits, after which the program calls the subroutine again. It repeats endlessly.
Unfortunately, the main program sometimes spontaneously (and repeatedly) cannot call the subprogram after a random period of time. A possible solution is to contact the original developers to get support, but at the same time, we need a quick fix to this problem.
I am trying to write a bash script that will track the output of a program, and when it sees a certain line, it will restart the machine (the program will start automatically at boot). The bash script should go through all the standard output to the screen until it sees a specific line. The program should also continue to process user input.
I have tried the following with limited success:
./program1 | ./watcher.sh
watcher.sh is basically the following:
while read line; do echo $line if [$line == "some string"] then
This seems to work fine, but leading spaces are separated by an echo statement, and the echo output hangs in the middle until the subroutine exits, at which point the rest of the output will be printed on the screen. Is there a better way to accomplish what I need to do?
Thanks in advance.
source share