WenChao WenChao - 1 year ago 100
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.

Answer Source
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\"")}'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download