Searching apache logs for iPhone User Agents

Updated , First Published by Pete Freitag

I was curious if anyone was using an iPhone to read my blog yet, I'm sure before too long we will all be optimizing our sites for 3.5" displays. To find out I did a little grep on my Apache log file and piped it to wc to count the number of matches:

grep 'iPhone;' access.log | wc -l

So far 370 hits including images, to take out requests for images I added:

grep 'iPhone;' access.log | fgrep --invert-match images | wc -l

That yields 106 requests, hello iPhone readers...

BTW the user agent for the iPhone looks like this:

Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3

Learn more about grep

There is a lot you can do with the grep linux command. Here, I'm using the --invert-match flag, which lets you perform a Inverted or Negative grep search. You can also do a case insensitive grep search, or even count files by extension using grep. Grep is one of the most useful linux commands to know!

Comments

Ben Nadel

Interesting... just went to my Google Analytics to search browsers. Searched for browsers containing "ipod", but nothing comes up. However, I did go to the site on someone's iPod (just to see what it looked like). So, not sure if Analytics is even picking them up. But then again, I just searched for MSIE and it came up with nothing, so I guess it is not storing useragents in that respect :(

Nick Rufa

I measured our site's PDA traffic during the first week of the iPhone launch. As a whole PDAs accounted for only a very modest percentage of our site's total traffic. The breakdown within that was: 29.1% Blackberry 28.4% Palm 25.2% WindowsCE 17.3% iPhone 17.3 % is pretty nice for a its first week on the market. I'll measure again in a few months is anyone's interested.

Nick Rufa

Sorry, the numbers in my prev. post may be hard to follow. Trying again (29.1% Blackberry) . (28.4% Palm) . (25.2% WindowsCE) . (17.3 % iPhone)

Pete Freitag

@Ben Did you mean to say you searched for browsers containing "iPhone", either way it doesn't look like Google Analytics reports on iPhone's yet.