Bash – output while reading keyboard input

bashshell-scriptterminal

I'm trying to write a script that will ssh into a box, start a processes that needs to be monitored (by a human) for success or failure then move onto the next box and repeat.

I've been trying to use tail or tail -f on the log that the process writes to, but I've yet to find a way to get the script to read keyboard input while the tail -f is running.

Ideally I'd like to tail -f the log until I see the process was successful, press a key and have the script move on, OR press another key if the startup errors out and exit the script.

Is this possible?

So far I've only come up with:

    #!/bin/bash
    kb=""
    until [ "$kb" == "n" ]; do
    tail /var/log/java-app.log
    read -t 1 kb
    done

It mostly works, but it's klunky. I'm starting up java apps and there are pauses so occasionally the same 10 lines are repeated and I have to hit enter to have the n acknowledged.
I'd really like to use tail -f and still read (ideally 2) different vars from the keyboard. Is this possible?

{edit}
I'm actually thinking that

tail -f /var/log/java-app.log | tee > ( grep -q "YADA YADA" )

Is my best bet. I can just Ctrl+C if I find errors.

Best Answer

#! /bin/bash

echo "Starting tail in the background..." 
tail -f input &
pid=$!
trap "kill $pid" EXIT
while true; do
        read kb
        test n = "$kb" && break
done
Related Question