linux - execute command in bash script until output exceeds certain value -


i use command parses video files frames , returning timecode, when found. @ moment, have execute command, wait, until values printed stdout reach desired position , abort execution using ctrl+c.

as have watch process , abort execution in right moment information need, thought, automate degree creating bash script.

i not certain, if can done in bash, don't know, how abort execution in connection values writes stdout.

the output of command looks like

0.040000 5.040000 10.040000 15.040000 18.060000 (...) 

i tried

until [[ "$timecode" -gt 30 ]];   timecode=$(mycommand)   sleep 0.1 done  echo "result: $timecode" 

or

while [[ "$timecode" -le 30 ]];   timecode=$(mycommand)   sleep 0.1 done  echo "result: $timecode" 

which both seem result in command being executed until finishes , afterwards rest of loop being processed. want evaluate output while command executes , break execution depending on output.

additional information

the command has no capability stopped @ point in stream. parses whole file , gives results unless signalled stop. first shot.

the execution time of command long files parse ~2gb. don't need frames of file few around given timecode, never let execute until finished.

the output of command varies file file, can't exact value. if knew exact value, wouldn't have it.

the destination time code - in example specified "-gt 30" - different every file have parse, have put command line parameter once script works. have make sure more last value of execution last 5 values. these 2 have ideas.

i'm totally stuck on 1 , have not idea google for.

thank input!

manuel


with answers of pskocik , kyle burton, able integrate suggested solution script. doesn't work , don't see, why.

here complete script including external command providing output:

 #!/usr/bin/env bash  set -eu -o pipefail   parser () {    local max="$1"    local max_int     max_int="${max%.*}"     while read tc;             local tc_int        tc_int="${tc%.*}"        echo $tc         if (( "$tc_int" >= "$max_int" ));          echo "over 30: $tc";          exec 0>&-          return 0        fi       done  }   ffprobe "$1" -hide_banner -select_streams v -show_entries frame=key_frame,best_effort_timestamp_time -of csv=nk=1:p=0:s="|" -v quiet | sed -ne "s/^1|//p" | parser 30 

i don't output "echo $tc" ffprobe running - can see in top. runs until stop script using ctrl+c.


thank kyle big efforts in this. i'd never come such conclusion. changed commandline of ffprobe suggestion

 ffprobe "$1" -hide_banner -select_streams v -show_entries frame=key_frame,best_effort_timestamp_time -of csv=nk=1:p=0:s="|" -v quiet | cut -f2 -d\| | parser 30 

and now, i'm getting results while ffprobe runs. but... way changed command returns frames, ffprobe finds , not keyframes. original output of ffprobe command looks like

 1|0.000000  0|0.040000  0|0.080000  0|0.120000  0|0.160000  0|0.200000  (...) 

the 0 @ beginning of line means: no keyframe. 1 @ beginning of line means: keyframe.

the script intended provide keyframes around timecode of video file. way changed command, provides frames of video file makes resulting output useless. has filtered lines starting 0 dropped.

as don't understand, why doesn't work sed, can try find solution try , error, facilitating different tools filter output. if filtering causes problem, might have hit wall here.

if have process a that's outputting stuff stdout , process b reads outputted stuff via pipe:

a | b 

all b has kill a when item outputted close standard input.

a sample b:

b() {     while read w;         case $w in some_pattern)exec 0>&-;; esac;          echo $w     done } 

this closing of stdin (filedescriptor 0) cause producer process killed sigpipe moment tries make next write.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -