Environment: armv7l GNU/Linux Debian Jessie, GNU
bash, v4.3.30(1)-release (arm-unknown-linux-gnueabihf).
do_stuff: a long running process which generates output to STDOUT
perlscript which does things based on the output.
I want to be able to restart the
compare_output.pl in case the process
compare_output.pl breaks (dies).
Even a simple
echo after the
while loop, (and after the
compare_output.pl), was unsuccessful.
Sadly I lack the idea how to actually do this in
Bonus for retaining the Cache/Puffer of the
while true; do ... do_stuff (which generates lot of output linewise to STDOUT) ... done | compare_output.pl #then something like this should happen, while retaining #the while loop and being able to "reattach" to the pipe. "compare_output died? restart it "
compare_output.pl breaks, (dies actually), which loses the whole pipe input. (Needless to say
compare_output.pl should not break, but that is another problem for another day).
compare_output breaks I want to be able to reuse the while loop, to be able to reattach to the pipe output. Losing one or a few lines is acceptable.
I tried using command substitution instead of a pipe:
while true; do ... do_stuff (which generates lot of output linewise) ... done < <( compare_output.pl ) # then something like this should happen, while retaining # the while loop and being able to "reattach" to the pipe. compare_output died? restart it "
restart_while_loop in case
compare_output.pl fails (dies)
read and adapted from Bash: cannot break out of piped "while read" loop; process substitution works
This other than obstructing output seems to not resolve my issue that I want to act after
When I did CTRL-C then my
echo test gets executed, which i did instead of the
compare_output.pl restart test.
do_stuff still runs for a long time.
Other than that I did read about piping and process substitution, lots of questions here but I seem to lack the right keyword to search for.
I know of Why is using a shell loop to process text considered bad practice? and understand that the way I do it is bad practice, but it's the situation I'm in which I currently cannot change.
So how can I get something to happen as soon as possible after
compare_output.pl dies? (process stops running, no
I am open for a full rewrite of the loop if that should be the only option to get this actually working. Currently I do not want to use other scripting languages, but if necessary I (somehow) could rewrite this in
perl but would like not to.