{"id":184885,"date":"2020-10-29T03:28:30","date_gmt":"2020-10-28T19:28:30","guid":{"rendered":"http:\/\/4563.org\/?p=184885"},"modified":"2020-10-29T03:28:30","modified_gmt":"2020-10-28T19:28:30","slug":"shell-%e6%80%8e%e4%b9%88%e5%b0%86%e5%8f%98%e9%87%8f%e4%b8%ad%e7%9a%84%e7%89%b9%e6%ae%8a%e5%ad%97%e7%ac%a6%e6%9b%bf%e6%8d%a2%e6%8e%89","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=184885","title":{"rendered":"shell \u600e\u4e48\u5c06\u53d8\u91cf\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u66ff\u6362\u6389"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  shell \u600e\u4e48\u5c06\u53d8\u91cf\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u66ff\u6362\u6389               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : awanganddong <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u7528 shell \u811a\u672c\u5199\u4e00\u4e2a\u65e5\u5fd7\u7684\u76d1\u63a7\u811a\u672c\u7ed9\u9489\u9489<\/p>\n<p>\u53d8\u91cf\u91cc\u8fb9\u7684\u4e00\u4e9b\u7279\u6b8a\u5b57\u7b26\u9700\u8981\u66ff\u6362\u6389\u3002\u6bd4\u5982\u5355\u5f15\u53f7\uff0c\u53cc\u5f15\u53f7\uff0c\u5927\u62ec\u53f7\u7b49<\/p>\n<p>\u6309\u7167$(var\/\u88ab\u66ff\u6362\u5b57\u7b26 \/\u66ff\u6362\u5b57\u7b26) \u4e00\u76f4\u4e0d\u6210\u529f<\/p>\n<p>\u6240\u4ee5\u60f3\u8981\u4e2a demo<\/p>\n<p>\u53e6\u5916\u611f\u89c9\u7528 shell \u5199\u6bd4 python \u5199\u9ebb\u70e6\u7684\u591a<\/p>\n<p>\u5927\u5bb6\u89c9\u5f97\u5462<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>16<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3987048\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : weixiangzhe <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             sed awk \u4e86\u89e3\u4e00\u4e0b\uff0c\u5927\u90e8\u5206\u6709 shell \u7684\u73af\u5883\u90fd\u6709 python \u5427\uff0c\u90a3\u5c31\u6539\u6210 python \u5457                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987049\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : codehz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u62ec\u53f7\u9519\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987050\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : webshe11 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u9ebb\u70e6\u7684\u8bdd\u8fd8\u662f\u6539 Python \u597d\u4f7f\uff0c\u6613\u8bfb\u53c8\u4e25\u8c28                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987051\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ai277014717 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5f88\u96be\u627e\u5230\u80fd\u8986\u76d6 100%case \u7684 printf \u8bd5\u8bd5\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987052\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ai277014717 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u8bd5\u8fc7\u7528 ruby \u6765\u505a<br \/>`printf &#8216;%sn&#8217; &#8220;$VAR&#8221; | ruby -e &#8220;require &#8216;json&#8217;; puts JSON.dump(ARGF.read)&#8221; | tr -d &#8216;n&#8217;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987053\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : codehz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7279\u6b8a\u7b26\u53f7\u7528\u659c\u6760\u8f6c\u4e49\uff0c\u5176\u4ed6\u7684\u4e0d\u53d8<br \/>${var\/&#8217;\/2333}                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987054\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : awanganddong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u662f\u6211\u5199\u7684 <br \/>\u5c06\u53d8\u91cf messageStr \u53d8\u91cf\u91cc\u8fb9\u7684\u5355\u5f15\u53f7\u548c\u53cc\u5f15\u53f7\u8f6c\u5316\u4e3a 0<br \/>\u7136\u800c\u5931\u8d25\u4e86<\/p>\n<p> ${messageStr\/'&#8221;\/0}<\/p>\n<p>\u86cb\u86cb\u5fe7\u4f24                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987055\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jfcherng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/tldp.org\/LDP\/abs\/html\/parameter-substitution.html<\/p>\n<p>${var\/Pattern\/Replacement}<br \/>First match of Pattern, within var replaced with Replacement.<\/p>\n<p>If Replacement is omitted, then the first match of Pattern is replaced by nothing, that is, deleted.<\/p>\n<p>${var\/\/Pattern\/Replacement}<br \/>Global replacement. All matches of Pattern, within var replaced with Replacement.<\/p>\n<p>As above, if Replacement is omitted, then all occurrences of Pattern are replaced by nothing, that is, deleted.                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987056\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : somalia <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u4e4b\u524d\u4e5f\u8981\u66ff\u6362\u6210 &#8216;*&#8217; \uff0c\u653e\u5f03 shell \u7528\u4e86 python                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987057\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : misaka19000 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6362 Python \u5199                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987058\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : awanganddong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jfcherng \u770b\u4e86\u6587\u6863\uff0c\u7279\u6b8a\u5b57\u7b26\u8fd8\u662f\u6ca1\u8f6c\u5316\u4e3a a<\/p>\n<p>&#8220;`<br \/>myDate=`date &#8220;+%Y-%m-%d %R&#8221;`<br \/>message=`less &#8216;laravel.log&#8217;|grep &#8216;local.ERROR&#8217;|grep &#8220;${myDate}&#8221;`<br \/>messageStr=&#8221;&#8221;<br \/>for line in $message<br \/>do<br \/> messageStr=&#8221;$messageStr$line&#8221;<br \/>done<br \/>if [ $messageStr ];then<br \/> messageStr=${messageStr\/\/'&#8221;\/a}<br \/> echo $messageStr;<br \/> curl &#8216;https:\/\/oapi.dingtalk.com\/robot\/send?access_token=token&#8217;<br \/> -H &#8220;Content-type: application\/json&#8221;<br \/> -X POST <br \/> -d &#8216;{&#8220;msgtype&#8221;: &#8220;text&#8221;,&#8221;text&#8221;: {&#8220;content&#8221;: &#8220;&#8216;$messageStr'&#8221;},&#8221;isAtAll&#8221;: true}&#8217;<br \/>fi<\/p>\n<p>&#8220;`                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987059\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jfcherng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u56e0\u70ba\u4f60\u6839\u672c\u7528\u932f\u554a&#8230; Pattern \u4e0d\u662f char list&#8230;<\/p>\n<p>[[email&#160;protected] Desktop]$ src=&#8221;x'&#8221;y&#8221;<br \/>[[email&#160;protected] Desktop]$ echo ${src\/\/[&#8216;&#8221;]\/a}<br \/>xaay                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987060\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : awanganddong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jfcherng \u611f\u8c22\u611f\u8c22<\/p>\n<p>\u53e6\u5916\u63d0\u4e2a\u95ee\u9898\uff0c[] \u8fd9\u4e2a\u4e0d\u592a\u61c2\uff0c\u6211\u770b\u6587\u6863\u4e0a\u8fb9\u4e5f\u6ca1\u4f53\u73b0                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987061\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jfcherng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5c31\u53ea\u662f\u4e00\u822c\u7684 regex<\/p>\n<p>\u770b\u5230 pattern \u901a\u5e38\u4e0d\u662f regex \u5c31\u662f\u80fd\u53ea\u80fd\u9802\u591a\u7528 wildcard (*)                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987062\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : awanganddong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6280\u672f\u624e\u5b9e\uff0c\u5c5e\u4e8e\u5927\u725b\u7ea7\u522b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3987063\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jfcherng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @awanganddong #15 \u8b1d\u8b1d\u4f60 \u4eca\u665a\u53ef\u4ee5\u958b\u5fc3\u5165\u7720\u4e86, \u4e0d\u904e regex \u662f\u5f88\u5e38\u898b\u7684\u6771\u897f \ud83d\ude42                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>shell \u600e\u4e48\u5c06\u53d8\u91cf\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/184885"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184885"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/184885\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184885"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}