4 ms·
tail -f log | grep keyword | while read line; do tmux send-keys -t 1:1.0 "$line"; done Really cool idea! But grep awaits EOF to pipe its result... (though it o
by hyp0 12y ago
tail -f log | grep keyword | while read line; do tmux send-keys -t 1:1.0 "$line"; done
Really cool idea! But grep awaits EOF to pipe its result... (though it outputs line-by-line if result is not piped onward)
How are you getting it to work? I found a --line-buffered option for GNU grep, but I'm using busybox grep...
EDIT OK, in case anyone else wants to know, found I could solve it by putting the grep inside the while loop instead (line=`echo $line | grep keyword`), but I'd still like to hear how you did it... BTW: entering "-" causes send-keys interprets it as an option.. I pr need some data cleansing...
- sp332 12y agoMaybe you can fix your '-' problem by putting '--' (like a blank option) in front of it. This tells send-keys not to interpret anything after the -- as an option.
- hyp0 12y agoGood idea, thanks, I know that idiom but didn't think of it. Interestingly, it's not in the tmux manpage, but I just tried it and it works. Cool!
- _jomo 12y agoCan't remember exactly how I did it. However I found something similar that waits for a command to complete sed instead of grep. sed exists after the first match: send_to_mc "/wb SomeWorld trim 100 15 C-m" sleep 1 send_to_mc "/wb trim confirm" tail -n 0 -F "logs/latest.log" | sed "/trimmed so far (100.0% done)/q" send_to_mc "/broadcast Chunk deletion done" send_to_mc is simply sending $1 + return to tmux: tmux send -t "$tmux_session" "$1" C-m /wb is a command from the WorldBorder [0] command that is (in this case) used to delete all chunks (which were generated for some reason) beyond the border. using while read line is probably the best option if you want to continuously check the logs You could also use awk isntead of grep: awk "/pattern/{print $0}" 0: https://github.com/Brettflan/WorldBorder https://github.com/Brettflan/WorldBorder EDIT: Completely misunderstood your problem. I thought grep wouldn't output to stdout until EOF. Seems like a loop is the only option