Linux终端实现根据应用包名过滤Logcat
#!/bin/bashif [[ ! -n $1 ]]; thencat <<EOFUsage: `basename $0`EOFexit 1fipackage_name=$1pid_list=$(adb shell ps| grep $package_name)if [[ -n $pid_list ]]; then# find pid, grep logcat wi
·
原理:首先根据包名使用ps命令查出当前运行的进程id,组合成grep表达式,过滤logcat!
#!/bin/bash
if [[ ! -n $1 ]]; then
cat <<EOF
Usage: `basename $0` <packagename>
EOF
exit 1
fi
package_name=$1
pid_list=$(adb shell ps| grep $package_name)
if [[ -n $pid_list ]]; then
# find pid, grep logcat with pid(s)
#convert to egrep format
pid_list=$(echo $pid_list|awk '{print $2}'|sed -r "s#(.*)#\\\(\[\ \]*\1\\\)#g"|tr '\n' '|')
#strip the last '|'
pid_list=${pid_list::-1}
adb logcat | grep --color -E "$pid_list"
fi
更多推荐
已为社区贡献1条内容
所有评论(0)