Post Reply

[Article]Workaround for grep and Logcat, dmesg, and last_kmsg on Windows

1st January 2013, 07:38 AM   |  #1  
OP Senior Member
Thanks Meter: 184
 
432 posts
Join Date:Joined: Apr 2012
In this article, I will explain some of the confusions that may occur whilst using grep in logcat, dmesg, kmsg and last_kmsg on different platforms,mainly between Unix(Linux based such as ubuntu, linux mint, fedora, BSD based such as netbsd, freebsd, and even Mac) and Windows(Windows XP, Windows Vista, Windows 7, Windows 8 and etc).

Requirements:
  1. Known about the existence of logcat, dmesg, kmsg, and last_kmsg and have tried logging it at least once
  2. Know some basic knowledge of batch/bash(cmd/terminal)
  3. Using Windows OS(The problem only lies on Windows, so if you're using Mac or Linux then you're fine)

Although this is a rather technical article, but I will make it as simple as possible for all of the users to understand

Sometimes, I will see some of the developers will issue similar to this:

Log Commands with Grep
Quote:

Logcat:
adb logcat | grep 'htc'

Dmesg:
adb shell dmesg | grep 'mp_decision'

last_kmsg:
adb shell cat /proc/last_kmsg | grep 'mp_decision'

So, the problem is?
The problem is that if you're using a Windows OS, Windows OS doesn't have grep installed, so your command would not run and you will see an error message like this:



Linux or Mac users will not have this problem as they have grep installed, so they are fine.

Workaround:
1. Install a Linux shell on Windows
2. Use a terminal app within the Android phone
3. Connect to the linux shell inside the Android Phone by using your computer
4. Use the built-in filters(for logcat ONLY)

Workaround #1
Quote:

You can simply click here and follow the simple steps to get a linux shell on your computer

Workaround #2
Quote:

You just need to download a terminal app from your phone and every command will work fine. You would need to omit the adb and adb shell keyword(refer below) in order for the command to work. A nice terminal app suggestion would be https://play.google.com/store/apps/d...roidterm&hl=en which you can simply download from Google Playstore

Workaround #3
Quote:

You can just type "adb shell" and press enter, then type your commands(omit all adb and adb shell keyword) and it will work just as like in workaround #2.

Example
Quote:

1. "adb shell" + enter
2. Choose the command that you wanted:

Logcat:
logcat | grep 'htc'

Dmesg:
dmesg | grep 'mp_decision'

last_kmsg:
cat /proc/last_kmsg | grep 'mp_decision'

Workaround #4
Quote:

This workaround is a workaround which only exists for logcat, because logcat have a filtering system that is built into it(makes us wonder why it is not built into dmesg and last_kmsg as well eh?).

For example, the grep command for the logcat above can be replaced by:

Quote:

adb logcat htc:V *:S

However, the downside is that you need to know the exact name of the app which is logged at the logcat in order to search for it while you can do a random keyword search with grep which helps a lot if you do not know what to look for.

For more information about the filtration, you can refer to http://developer.android.com/tools/d...gging-log.html

Conclusion:
Hopefully, after reading this article, you will know how to deal with grep when you're on Windows OS

Do drop me a question or two if you have something that you don't understand and stay tuned for more articles!
Last edited by wcypierre; 1st January 2013 at 08:01 AM.
The Following 2 Users Say Thank You to wcypierre For This Useful Post: [ View ]
1st January 2013, 07:41 AM   |  #2  
nikufellow's Avatar
Senior Member
simcity
Thanks Meter: 811
 
2,849 posts
Join Date:Joined: May 2012
Actually most of these are already known but neverthless nice guide

Ps: Limited to 8 thanks per day so will thank later !
1st January 2013, 09:12 AM   |  #3  
OP Senior Member
Thanks Meter: 184
 
432 posts
Join Date:Joined: Apr 2012
Quote:
Originally Posted by nikufellow

Actually most of these are already known but neverthless nice guide

Ps: Limited to 8 thanks per day so will thank later !

I do agree that the last 3 solutions are common but there's still people who doesn't know about it.

But I think that there'll be quite some people who doesn't know about the first workaround though, as it is not covered in most tutorials(unless you're looking at a rom building tutorial on windows), or do you?

Sure thing and thanks in advance
13th March 2014, 07:32 PM   |  #4  
ravike14's Avatar
Senior Member
Flag Colombo
Thanks Meter: 1,077
 
1,303 posts
Join Date:Joined: Feb 2013
Donate to Me
More
Found it when I needed the most, the 1st method.. Thanks, simple but a good article

Sent from my HTC_Amaze_4G using XDA Premium 4 mobile app
13th March 2014, 07:55 PM   |  #5  
OP Senior Member
Thanks Meter: 184
 
432 posts
Join Date:Joined: Apr 2012
Quote:
Originally Posted by ravike14

Found it when I needed the most, the 1st method.. Thanks, simple but a good article

Sent from my HTC_Amaze_4G using XDA Premium 4 mobile app

You're welcome Glad to be of help even though this thread is already at least one year old
13th March 2014, 08:47 PM   |  #6  
ravike14's Avatar
Senior Member
Flag Colombo
Thanks Meter: 1,077
 
1,303 posts
Join Date:Joined: Feb 2013
Donate to Me
More
Quote:
Originally Posted by wcypierre

You're welcome Glad to be of help even though this thread is already at least one year old

i found it useful after year hehe....hey for some weird reason the method 1 and 3 fails when it comes to '' dmesg | grep 'xxx' > dmesg.txt '' commad :/ the text comes empty even tho the grep related logs are there in the normal dmesg when i try method 1 using [Msysgit]..when i try the 3rd method it just say read only file system and stops if i choose the output as a .txt file..when i enter 'dmesg | grep 'xxx' without '.txt' it do nothing :/
Last edited by ravike14; 13th March 2014 at 08:54 PM.
13th March 2014, 09:31 PM   |  #7  
OP Senior Member
Thanks Meter: 184
 
432 posts
Join Date:Joined: Apr 2012
Quote:
Originally Posted by ravike14

i found it useful after year hehe....hey for some weird reason the method 1 and 3 fails when it comes to '' dmesg | grep 'xxx' > dmesg.txt '' commad :/ the text comes empty even tho the grep related logs are there in the normal dmesg when i try method 1 using [Msysgit]..when i try the 3rd method it just say read only file system and stops if i choose the output as a .txt file..when i enter 'dmesg | grep 'xxx' without '.txt' it do nothing :/

For the 1st method, there won't be any output as it is redirected to the file 'dmesg.txt'. Or you're indicating that the dmesg.txt file is empty?
For the 3rd one, are you running it on a rooted phone or stock bootloader?

Last but not least, can you give me an example of the command that you had tried for the 1st and 3rd method and a snippet of the dmesg.txt so that I can look into your problem?
13th March 2014, 09:59 PM   |  #8  
ravike14's Avatar
Senior Member
Flag Colombo
Thanks Meter: 1,077
 
1,303 posts
Join Date:Joined: Feb 2013
Donate to Me
More
Quote:
Originally Posted by wcypierre

For the 1st method, there won't be any output as it is redirected to the file 'dmesg.txt'. Or you're indicating that the dmesg.txt file is empty?
For the 3rd one, are you running it on a rooted phone or stock bootloader?

Last but not least, can you give me an example of the command that you had tried for the 1st and 3rd method and a snippet of the dmesg.txt so that I can look into your problem?

The dmesg.txt is empty, not even adb daemon text is there.. And yea I'm rooted and s-off.... I tried

For 1st method

adb shell dmesg | grep 'wl127xx' > dmesg.txt

For 3rd i tried

dmesg grep 'wl127xx'

And

dmesg grep 'wl127xx' > dmesg.txt

Tried the 3rd method even in Linux shell still a no go the txt is empty it just creates it and that's it.. When I execute the command without 'grep' I get the dmesg logs correctly.. But I really want the grep part lol..

Sent from my HTC_Amaze_4G using XDA Premium 4 mobile app
13th March 2014, 10:17 PM   |  #9  
OP Senior Member
Thanks Meter: 184
 
432 posts
Join Date:Joined: Apr 2012
Quote:
Originally Posted by ravike14

The dmesg.txt is empty, not even adb daemon text is there.. And yea I'm rooted and s-off.... I tried

For 1st method

adb shell dmesg | grep 'wl127xx' > dmesg.txt

For 3rd i tried

dmesg grep 'wl127xx'

And

dmesg grep 'wl127xx' > dmesg.txt

Tried the 3rd method even in Linux shell still a no go the txt is empty it just creates it and that's it.. When I execute the command without 'grep' I get the dmesg logs correctly.. But I really want the grep part lol..

Sent from my HTC_Amaze_4G using XDA Premium 4 mobile app

can you copy the text snippet of the dmesg that contains the 'wl127xx' text then? A screenshot or the actual text would do
Last edited by wcypierre; 13th March 2014 at 10:56 PM.
14th March 2014, 07:09 AM   |  #10  
ravike14's Avatar
Senior Member
Flag Colombo
Thanks Meter: 1,077
 
1,303 posts
Join Date:Joined: Feb 2013
Donate to Me
More
Quote:
Originally Posted by wcypierre

can you copy the text snippet of the dmesg that contains the 'wl127xx' text then? A screenshot or the actual text would do

if you mean the normal dmesg text,
Attached Files
File Type: txt dmesg.txt - [Click for QR Code] (132.8 KB, 5 views)

Post Reply Subscribe to Thread

Tags
dmesg, grep, kmsg, logcat, workaround
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Android General by ThreadRank