evry
evry copied to clipboard
discussion: extended looping features
would there be any interest in extending the features of this cli tool to match loop-rs I was searching for the closest thing written in Go and this seems to be it.
Loops in bash are surprisingly complicated and fickle! I wanted a simple and intuitive way to write controllable loops that:
Run on controllable timers! $ loop 'ls' --every 10s
Have custom counters! $ loop 'touch $COUNT.txt' --count-by 5
Loop until output matches a condition! $ loop --until-contains 200 -- ./get_response_code.sh --site mysite.biz
Loop until a certain time! $ loop './poke_server' --for-duration 8h
Loop until a program succeeds (or fails!) $ loop './poke_server' --until-success
Iterate over the standard input! $ cat files_to_create.txt | loop 'touch $ITEM'
Get a summary of the runs! $ loop 'ls' --for-duration 10min --summary
Run until output changes or stays the same between invocations! $ loop --until-changes date +%s $ loop --until-same date +%s
@c-nv-s Thank you for your comment.
I think loop-rs is very interesting. However, the concept seems to be different from evry. The main function of loop-rs is to loop the execution of commands, while evry's main function is to split STDIN.
ok. I just thought that evry's features seem to currently be a subset of what loop-rs is i.e. controllable counters, and iterate over stdin.
If you ever feel inspiration to do a go implementation of loop-rs then I think you are already part way there.
This is a simple question, but can loop-rs split STDIN into 5-line segments and process them, or count the number of lines every 10 seconds? (This is the main feature of evry)
You can see that it holds each line of input from stdin in a variable called $ITEM, so I guess you would have to use a combination of the counter $COUNT to determine how many lines you want to process. i.e. append each $ITEM to $ITEMS and if wc -l of $ITEMS is 5 then do something and reset.
How would you write the following command in loop-rs?
$ tail -F access.log | evry -l 1000 -c 'somecommand'
This command passes the access log to somecommand as STDIN in 1,000-line segments.
Very sorry for the late response. I didn't have access to loop when you asked and then life took over for a while.
yes the evry expression of that command will be more terse
cat access.log | loop 'cumulativeString="${cumulativeString} $ITEM" ; if [ $(( $COUNT % 1000 )) -eq 0 ] ;then somecommand "${cumulativeString}" ; fi'
as you can see loop can read from stdin but it just doesn't follow stdin like evry does
if you wanted to track changes to the access log you would have to workaround with inotify-tools or something.
loop 'inotifywait --event modify ./access.log && if [ $(( $COUNT % 1000 )) -eq 0 ]; then tail -n 1000 ./access.log | xargs -I "{}" somecommand {}; fi ' --until-fail
happy new year by the way