WenChao WenChao - 2 months ago 6
Bash Question

How to run command once line is detected from ADB Logcat?

As the titles says, I need to run some command/script after a particular log is printed from ADB Logcat, how can I go about it?
Have tried things like

adb logcat | grep whatever | while read line do echo 'got it' done


but it doesn't work.
Thanks.

PS. PS.
Answer
adb logcat |grep --line-buffered 'whatever' | while read ; do echo "got it" ; done  

Or using awk :

General syntax :

tail -f <log file> | awk '/<string to look for>/ { system("<shell command>")}'

Command for your case :

adb logcat |awk '/whatever/ { system("echo \"got it\"")}'