{"id":269,"date":"2020-12-05T17:21:48","date_gmt":"2020-12-05T09:21:48","guid":{"rendered":"http:\/\/blog.refusea.com\/?p=269"},"modified":"2020-12-05T17:21:48","modified_gmt":"2020-12-05T09:21:48","slug":"linux-%e6%97%a5%e5%bf%97%e5%a4%84%e7%90%86%e5%88%a9%e5%99%a8-awk","status":"publish","type":"post","link":"https:\/\/refusea.com\/?p=269","title":{"rendered":"Linux \u65e5\u5fd7\u5904\u7406\u5229\u5668 awk"},"content":{"rendered":"<h2>\u76ee\u6807<\/h2>\n<p>\u901a\u8fc7\u5206\u6790 error.log \u65e5\u5fd7\uff0c\u7edf\u8ba1\u51fa\u6709\u54ea\u4e9b\u5f02\u5e38\u53ca\u5176\u6570\u91cf<\/p>\n<h2>\u5206\u6790<\/h2>\n<p>\u9996\u5148\u8981\u770b\u4e0b\u5f02\u5e38\u65e5\u5fd7\u7684\u683c\u5f0f<\/p>\n<pre><code>2017-07-19 01:03:41,399 ERROR [qtp738355611-33898] [com.refusea.web.AppInfoController] - appUpdate:\njava.lang.NumberFormatException: !hex 215\n        at org.eclipse.jetty.util.TypeUtil.convertHexDigit(TypeUtil.java:375)\n        at org.eclipse.jetty.util.UrlEncoded.decodeUtf8To(UrlEncoded.java:545)\n        at org.eclipse.jetty.util.UrlEncoded.decodeTo(UrlEncoded.java:601)\n        at org.eclipse.jetty.server.Request.extractParameters(Request.java:298)\n        at org.eclipse.jetty.server.Request.getParameter(Request.java:708)<\/code><\/pre>\n<p>\u7ecf\u8fc7\u5206\u6790\uff0c\u53d1\u73b0\u6bcf\u6b21\u6253\u5370\u5f02\u5e38\u7684\u683c\u5f0f\u5982\u4e0b<\/p>\n<ul>\n<li>\u7b2c\u4e00\u884c\n<ul>\n<li>\u65f6\u95f4\uff0c\u65e5\u5fd7\u7ea7\u522b\uff0c\u7ebf\u7a0b\u4fe1\u606f\uff0c\u7c7b\uff0c\u5f02\u5e38\u6d88\u606f\uff08\u4e1a\u52a1\uff09<\/li>\n<\/ul>\n<\/li>\n<li>\u7b2c\u4e8c\u884c\u53ca\u540e\u7eed\n<ul>\n<li>\u5f02\u5e38\u5806\u6808\u4fe1\u606f\uff0c\u5176\u4e2d\u7b2c\u4e8c\u884c\u662f\u5f02\u5e38\u7684\u7c7b\u540d\u53ca\u5f02\u5e38\u6d88\u606f<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u90a3\u4e48\u6211\u4eec\u7684\u601d\u8def\u662f<\/p>\n<ul>\n<li>\u627e\u5230\u6709\u7b2c\u4e09\u4e2a\u57df\u4e3a ERROR \u7684\u90a3\u4e00\u884c<\/li>\n<li>\u8be5\u884c\u7684\u4e0b\u4e00\u884c\u5c31\u662f\u6211\u4eec\u9700\u8981\u7edf\u8ba1\u5206\u6790\u7684\u90a3\u4e00\u884c<\/li>\n<\/ul>\n<h2>\u547d\u4ee4<\/h2>\n<pre><code class=\"language-bash\">zcat refusea-error.log.20170719.gz | awk -v line=0 &#039;{if (line==1) print($0); if ($3==&quot;ERROR&quot;) {line=1;} else {line=0;}}&#039; | sort | uniq -c | sort -rn<\/code><\/pre>\n<p>\u547d\u4ee4\u6267\u884c\u7ed3\u679c\u5982\u4e0b<\/p>\n<pre><code class=\"language-bash\">54 redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool\n54 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:\n28 org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: org.eclipse.jetty.io.EofException; nested exception is com.google.gson.JsonIOException: org.eclipse.jetty.io.EofException\n12 org.springframework.dao.DeadlockLoserDataAccessException:\n 8 org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.\n 7 java.lang.IllegalArgumentException: fromIndex(150) &gt; toIndex(127)\n 6 redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out\n 4 org.springframework.dao.DataIntegrityViolationException:\n 4 java.lang.IllegalStateException: Optional long parameter &#039;timestamp&#039; is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.\n 3 org.eclipse.jetty.io.EofException\n 3 java.lang.NullPointerException\n 3 java.lang.IllegalArgumentException: fromIndex(150) &gt; toIndex(131)\n 3 com.alibaba.fastjson.JSONException: syntax error, pos 720\n 1 org.springframework.dao.CannotAcquireLockException:\n 1 java.lang.NumberFormatException: !hex 71\n 1 java.lang.NumberFormatException: !hex 34\n 1 java.lang.NumberFormatException: !hex 215\n 1 java.lang.NumberFormatException: !hex 15\n 1 com.alibaba.fastjson.JSONException: unclosed string : \ufffd\n 1 com.alibaba.fastjson.JSONException: unclosed string : \u0302\n 1 com.alibaba.fastjson.JSONException: syntax error, unexpect token error\n 1 com.alibaba.fastjson.JSONException: not match &#039;:&#039; - ,\n 1 com.alibaba.fastjson.JSONException: error parse false<\/code><\/pre>\n<h3>zcat<\/h3>\n<p>\u548c cat \u547d\u4ee4\u7c7b\u4f3c\uff0c\u4e0d\u8fc7\u4f5c\u7528\u7684\u5bf9\u8c61\u662f\u538b\u7f29\u6587\u4ef6<\/p>\n<h3>|<\/h3>\n<p>\u8fd9\u662f linux \u7ba1\u9053\u7b26\uff0c\u4ed6\u7684\u4f5c\u7528\u662f\u628a\u7ba1\u9053\u7b26\u5de6\u8fb9\u547d\u4ee4\u7684\u8f93\u51fa\u5f53\u4f5c\u7ba1\u9053\u7b26\u53f3\u8fb9\u547d\u4ee4\u7684\u8f93\u5165\uff0c\u793a\u4f8b<\/p>\n<pre><code class=\"language-bash\">ps aux | grep &#039;java&#039;<\/code><\/pre>\n<h3>awk<\/h3>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u5f88\u590d\u6742\uff0c\u8fd9\u91cc\u89e3\u91ca\u4e00\u4e0b\u524d\u9762\u7edf\u8ba1\u5f02\u5e38\u6570\u91cf\u7684\u547d\u4ee4<\/p>\n<pre><code class=\"language-bash\">awk -v line=0 &#039;{if (line==1) print($0); if($3==&quot;ERROR&quot;) {line=1;} else {line=0;}}&#039;<\/code><\/pre>\n<p>\u6211\u4eec\u77e5\u9053\uff0cawk \u547d\u4ee4\u4f1a\u5bf9\u8f93\u5165\u7684\u6587\u672c\u9010\u884c\u8fdb\u884c\u5904\u7406\uff0c\u7c7b\u4f3c\u4ee5\u4e0b\u7684\u5904\u7406\u8fc7\u7a0b<\/p>\n<pre><code>while \u5f53\u524d\u884c\u4e0d\u4e3a\u7a7a\n    \u5904\u7406 \u5f53\u524d\u884c\n    \u79fb\u52a8\u5230 \u4e0b\u4e00\u884c<\/code><\/pre>\n<p>\u90a3\u4e48\u4e0a\u9762\u7684\u547d\u4ee4\u5c31\u53ef\u4ee5\u8fd9\u6837\u7406\u89e3<\/p>\n<pre><code class=\"language-bash\"># \u6307\u793a\u5f53\u524d\u884c\u662f\u5426\u5305\u542b\u5f02\u5e38\u4fe1\u606f \nline = 0\nwhile \u5f53\u524d\u884c\u4e0d\u4e3a\u7a7a\n    if line == 1 \n        \u8f93\u51fa\u5f53\u524d\u884c\n    if $3 == &#039;ERROR&#039;\n        line = 1\n    else\n        line = 0<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u7684\u4f5c\u7528\u5c31\u662f\u627e\u5230\u542b\u6709 ERROR \u7684\u884c\uff0c\u5e76\u5c06\u5176\u4e0b\u4e00\u884c\u6253\u5370\u8f93\u51fa<\/p>\n<h3>sort<\/h3>\n<p>\u4ee5\u884c\u4e3a\u5355\u4f4d\u5bf9\u6587\u672c\u8fdb\u884c\u6392\u5e8f<\/p>\n<h3>uniq<\/h3>\n<p>\u5220\u9664\u91cd\u590d\u7684\u884c\uff0c\u53c2\u6570<br \/>\n-c \u5728\u8f93\u51fa\u884c\u524d\u9762\u52a0\u4e0a\u6bcf\u884c\u5728\u8f93\u5165\u6587\u4ef6\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\u3002<br \/>\n-d \u4ec5\u663e\u793a\u91cd\u590d\u884c\u3002<br \/>\n-u \u4ec5\u663e\u793a\u4e0d\u91cd\u590d\u7684\u884c<\/p>\n<h2>\u4e00\u4e9b\u5e38\u7528\u7684 awk \u547d\u4ee4<\/h2>\n<p>\u5206\u6790 nginx \u7684\u65e5\u5fd7\u6587\u4ef6<\/p>\n<h3>\u7edf\u8ba1\u5404\u4e2a\u63a5\u53e3\u7684 pv<\/h3>\n<pre><code class=\"language-bash\">awk &#039;{if($14==&quot;\/proxy&quot;) {print $15} else {print $14}}&#039; xxx_access.log|sort|uniq -c|sort -rn|head -n 20<\/code><\/pre>\n<h3>\u7edf\u8ba1\u6162\u63a5\u53e3<\/h3>\n<p>\u54cd\u5e94\u65f6\u95f4\u8d85\u8fc7 1 \u79d2\u7684\u63a5\u53e3\u6570<\/p>\n<pre><code class=\"language-bash\">awk &#039;{if($9&gt;1)print $0}&#039;|wc -l<\/code><\/pre>\n<p>\u5982\u679c\u60f3\u8981\u8f93\u51fa\u5177\u4f53\u662f\u54ea\u4e9b\u63a5\u53e3\uff0c\u53ef\u4ee5\u7ed3\u5408\u4e0a\u9762\u547d\u4ee4<\/p>\n<pre><code class=\"language-bash\">awk &#039;{if($9&gt;1)print $0}&#039;|awk &#039;{if($14==&quot;\/proxy&quot;) {print $15} else {print $14}}&#039; |sort|uniq -c|sort -rn|head -n 20<\/code><\/pre>\n<p>\u5982\u679c\u8981\u5206\u65f6\u6bb5\u7edf\u8ba1<\/p>\n<pre><code class=\"language-bash\">awk &#039;{if($9&gt;1)print $1}&#039;|awk -F &#039;:&#039; &#039;{print $1}&#039;|uniq -c<\/code><\/pre>\n<h3>\u7edf\u8ba1\u54cd\u5e94\u7801<\/h3>\n<pre><code class=\"language-bash\">awk &#039;{print $2}&#039;| sort | uniq -c | sort -rn<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6807 \u901a\u8fc7\u5206\u6790 error.log \u65e5\u5fd7\uff0c\u7edf\u8ba1\u51fa\u6709\u54ea\u4e9b\u5f02\u5e38\u53ca\u5176\u6570\u91cf \u5206\u6790 \u9996\u5148\u8981\u770b\u4e0b\u5f02\u5e38\u65e5\u5fd7\u7684\u683c\u5f0f 2017- [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[25],"class_list":["post-269","post","type-post","status-publish","format-standard","hentry","category-linux","tag-awk"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux \u65e5\u5fd7\u5904\u7406\u5229\u5668 awk - \u62d2\u6d77\u7a7a\u95f4<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/refusea.com\/?p=269\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"refusea.com\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/refusea.com\/?p=269#article\",\"isPartOf\":{\"@id\":\"https:\/\/refusea.com\/?p=269\"},\"author\":{\"name\":\"refusea.com\",\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df\"},\"headline\":\"Linux \u65e5\u5fd7\u5904\u7406\u5229\u5668 awk\",\"datePublished\":\"2020-12-05T09:21:48+00:00\",\"dateModified\":\"2020-12-05T09:21:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/refusea.com\/?p=269\"},\"wordCount\":19,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df\"},\"keywords\":[\"awk\"],\"articleSection\":[\"Linux\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/refusea.com\/?p=269#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/refusea.com\/?p=269\",\"url\":\"https:\/\/refusea.com\/?p=269\",\"name\":\"Linux \u65e5\u5fd7\u5904\u7406\u5229\u5668 awk - \u62d2\u6d77\u7a7a\u95f4\",\"isPartOf\":{\"@id\":\"https:\/\/refusea.com\/#website\"},\"datePublished\":\"2020-12-05T09:21:48+00:00\",\"dateModified\":\"2020-12-05T09:21:48+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/refusea.com\/?p=269#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/refusea.com\/?p=269\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/refusea.com\/?p=269#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/refusea.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux \u65e5\u5fd7\u5904\u7406\u5229\u5668 awk\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/refusea.com\/#website\",\"url\":\"https:\/\/refusea.com\/\",\"name\":\"\u62d2\u6d77\u7a7a\u95f4\",\"description\":\"\u62d2\u6d77\u7684\u4e2a\u4eba\u535a\u5ba2\",\"publisher\":{\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/refusea.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df\",\"name\":\"refusea.com\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7f7489b4afdbd952db64e7a6704d1258?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7f7489b4afdbd952db64e7a6704d1258?s=96&d=mm&r=g\",\"caption\":\"refusea.com\"},\"logo\":{\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/refusea.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linux \u65e5\u5fd7\u5904\u7406\u5229\u5668 awk - \u62d2\u6d77\u7a7a\u95f4","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/refusea.com\/?p=269","twitter_misc":{"\u4f5c\u8005":"refusea.com","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/refusea.com\/?p=269#article","isPartOf":{"@id":"https:\/\/refusea.com\/?p=269"},"author":{"name":"refusea.com","@id":"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df"},"headline":"Linux \u65e5\u5fd7\u5904\u7406\u5229\u5668 awk","datePublished":"2020-12-05T09:21:48+00:00","dateModified":"2020-12-05T09:21:48+00:00","mainEntityOfPage":{"@id":"https:\/\/refusea.com\/?p=269"},"wordCount":19,"commentCount":0,"publisher":{"@id":"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df"},"keywords":["awk"],"articleSection":["Linux"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/refusea.com\/?p=269#respond"]}]},{"@type":"WebPage","@id":"https:\/\/refusea.com\/?p=269","url":"https:\/\/refusea.com\/?p=269","name":"Linux \u65e5\u5fd7\u5904\u7406\u5229\u5668 awk - \u62d2\u6d77\u7a7a\u95f4","isPartOf":{"@id":"https:\/\/refusea.com\/#website"},"datePublished":"2020-12-05T09:21:48+00:00","dateModified":"2020-12-05T09:21:48+00:00","breadcrumb":{"@id":"https:\/\/refusea.com\/?p=269#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/refusea.com\/?p=269"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/refusea.com\/?p=269#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/refusea.com\/"},{"@type":"ListItem","position":2,"name":"Linux \u65e5\u5fd7\u5904\u7406\u5229\u5668 awk"}]},{"@type":"WebSite","@id":"https:\/\/refusea.com\/#website","url":"https:\/\/refusea.com\/","name":"\u62d2\u6d77\u7a7a\u95f4","description":"\u62d2\u6d77\u7684\u4e2a\u4eba\u535a\u5ba2","publisher":{"@id":"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/refusea.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df","name":"refusea.com","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/refusea.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7f7489b4afdbd952db64e7a6704d1258?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7f7489b4afdbd952db64e7a6704d1258?s=96&d=mm&r=g","caption":"refusea.com"},"logo":{"@id":"https:\/\/refusea.com\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/refusea.com"]}]}},"_links":{"self":[{"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/posts\/269"}],"collection":[{"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/refusea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=269"}],"version-history":[{"count":2,"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/posts\/269\/revisions"}],"predecessor-version":[{"id":271,"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/posts\/269\/revisions\/271"}],"wp:attachment":[{"href":"https:\/\/refusea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/refusea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/refusea.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}