Run tail -f for specific time in bash script

I need a script that will run a series of tail -f commands and output them to a file. I need tail -f run a certain amount of time for grep specific words. The reason is that this is a specific time, because some of these values ​​are not immediately displayed, as this is a live log.

How can I run something like this to say 20 seconds, output the grep command, and then move on to the next command?

 tail -f /example/logs/auditlog | grep test 

thanks

+4
source share
3 answers
 timeout 20 tail -f /example/logs/auditlog | grep test 
+12
source
 tail -f /example/logs/auditlog | grep test & pid=$! sleep 20 kill $pid 
+4
source

How about this:

 for (( N=0; $N < 20 ; N++)) ; do tail -f /example/logs/auditlog | grep test ; sleep 1 ; done 

EDIT: I misunderstood your question, sorry. You want something like this:

 tail -f /example/logs/auditlog | grep test sleep 20 
0
source

Source: https://habr.com/ru/post/1479074/


All Articles