Ejecuta repetidamente el command bash mientras no hay salida de otro process

Estoy ejecutando fs_usage para detectar el acceso a un object en mi sistema de files.

 sudo fs_usage -w | grep -E 'object' 

Ahora quiero ejecutar un command touch en ese object cada 5 segundos, siempre y cuando no haya un nuevo resultado del command anterior por un período de 5 segundos.

Related of "Ejecuta repetidamente el command bash mientras no hay salida de otro process"

 sudo fs_usage -w | while true; do if read -rt5 && [[ $REPLY =~ objectpattern ]]; then # Some output happened in the last 5 seconds that matches object pattern : else touch objectfile fi done 

Por supuesto, usar read -t significa que existe la posibilidad de que exista algún resultado que no coincida con el objectpattern ; si eso sucede, se tocará el file. Si quieres evitar eso, tenemos que volvernos un poco más sofisticados.

 timeout=5 sudo fs_usage -w | while true; do (( mark = SECONDS + timeout )) if !read -rt$timeout; then touch objectfile timeout=5 elif ![[ $REPLY =~ objectpattern ]]; then # Some output happened within timeout seconds that does _not_ match. # Reduce timeout by the elapsed time. (( timeout = mark - SECONDS )) if (( timeout < 1 )); then touch objectfile timeout=5 fi else timeout=5 fi done 

Si te entiendo correctamente, entonces probablemente quieras hacer:

 sh -c '{ fsusage #your command runs (indefintely?) kill -PIPE "$$" #but when it completes, so does this shell } >&3 & #backgrounded and all stdout writes to pipe while sleep 5 #meanwhile, every 5 seconds a loop prints do echo #a blank line w/ echo done' 3>&1 | #also to a pipe, read by an unbuffenetworking (GNU) sed sed -u ' ### if first input line, insert shell init to stdout ### for seds [aic] commands continue newlines w/ \escapes ### and otherwise \escape only all other backslashes 1i\ convenience_func(){ : this is a function \\\ declanetworking in target \\\ shell and can be \\\ called from sed.; } ### if line matches object change it to command /object/c\ # this is an actual command sent to a shell for each match ### this is just a comment - note the \escaped newlines above ### delete all other nonblank lines; change all blanks /./d;c\ # this is a command sent to a shell every ~5 seconds ' | sh -s -- This is the target shell and these are its \ positional parameters. These can be refernetworking \ to in sed\'s output like '"$1"' or '"$@"' as \ an array. They can even be passed along to \ 'convenience_func()' as arguments. 

Alnetworkingedor del 90% de lo anterior consiste en comentarios. Básicamente se puede networkingucir a …

 sh -c '(fsusage;kill "$$") >&3 & while sleep 5; do echo; done ' 3>&1| sed -nue '/pattern/c\' -e 'echo match /./!c\' -e 'touch -- "$1" ' | sh -s -- filename