{"id":936,"date":"2017-01-16T13:00:17","date_gmt":"2017-01-16T13:00:17","guid":{"rendered":"http:\/\/www.haxed.me.uk\/?p=936"},"modified":"2017-01-25T11:29:36","modified_gmt":"2017-01-25T11:29:36","slug":"checking-webserver-logs-generating-hit-counts","status":"publish","type":"post","link":"https:\/\/haxed.me.uk\/index.php\/2017\/01\/16\/checking-webserver-logs-generating-hit-counts\/","title":{"rendered":"Checking Webserver Logs and generating hit counts"},"content":{"rendered":"<p>So, I&#8217;ve been meaning to do this for a while. I&#8217;m sure your all familiar with this crappy oneliner where you&#8217;ll check the hits using wc -l against a webserver log for a given hour and use for i in seq or similar to get the last 10 minutes data, or the last 59 minutes. But getting hours and days is a bit harder. You need some additional nesting, and, it isn&#8217;t difficult for you to do at all!<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nfor i in 0{1..9}; do echo &quot;16\/Jan\/2017:06:$i&quot;; grep &quot;16\/Jan\/2017:06:$i&quot; \/var\/log\/httpd\/soemsite.com-access_log | wc -l ; done\r\n<\/pre>\n<p>I improved this one, quite significantly by adding an additional for j, for the hour, and adding an additional 0 in front of {1..9}, this properly is matching the Apache2 log format and allows me to increment through all the hours of the day. to present ;-D All that is missing is some error checking when the last date in the file is, im thinking a tail and grep for the timecode from the log should be sufficient.<\/p>\n<p>Here is the proud oneliner I made for this!<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nfor j in 0{1..9}; do for i in 0{1..9} {10..59}; do echo &quot;16\/Jan\/2017:$j:$i&quot;; grep &quot;16\/Jan\/2017:06:$i&quot; \/var\/log\/httpd\/website.com-access_log | wc -l ; done; done\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So, I&#8217;ve been meaning to do this for a while. I&#8217;m sure your all familiar with this crappy oneliner where you&#8217;ll check the hits using wc -l against a webserver log for a given hour and use for i in &hellip; <a href=\"https:\/\/haxed.me.uk\/index.php\/2017\/01\/16\/checking-webserver-logs-generating-hit-counts\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,19,28,74,7,29],"tags":[],"class_list":["post-936","post","type-post","status-publish","format-standard","hentry","category-apache","category-bash","category-interweb","category-logging","category-management-tools","category-monitoring"],"_links":{"self":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=936"}],"version-history":[{"count":3,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/936\/revisions"}],"predecessor-version":[{"id":954,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/936\/revisions\/954"}],"wp:attachment":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}