{"id":5674,"date":"2024-04-13T16:57:13","date_gmt":"2024-04-13T08:57:13","guid":{"rendered":"https:\/\/ixyzero.com\/blog\/?p=5674"},"modified":"2024-04-13T16:57:13","modified_gmt":"2024-04-13T08:57:13","slug":"%e9%80%9a%e8%bf%87%e4%b8%80%e4%b8%aa%e4%be%8b%e5%ad%90%e5%ad%a6%e4%b9%a0%e4%b8%80%e4%b8%8bawk%e8%84%9a%e6%9c%ac%e7%9a%84%e7%bc%96%e5%86%99","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/5674.html","title":{"rendered":"\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u5b66\u4e60\u4e00\u4e0bawk\u811a\u672c\u7684\u7f16\u5199"},"content":{"rendered":"\n<p>=Start=<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7f18\u7531\uff1a<\/h4>\n\n\n\n<p>\u901a\u8fc7\u5b66\u4e60\u4e00\u4e2a\u7528awk\u5bf9 <code>sfltool dumpbtm<\/code> \u547d\u4ee4\u8f93\u51fa\u505a\u89e3\u6790\u7684\u6848\u4f8b\u6765\u5b66\u4e60\u4e00\u4e0bawk\u7f16\u7a0b\u7684\u77e5\u8bc6\uff08\u56e0\u4e3a\u8981\u89e3\u6790\u7684\u6587\u672c\u5185\u5bb9\u975e\u5e38\u89c4\u683c\u5f0f\uff0c\u662f\u4e00\u6bb5\u4e00\u6bb5\u7684\uff0c\u7b80\u5355\u60f3\u4e86\u60f3\uff0c\u597d\u50cf\u7528Python\u6765\u5199\u8fd8\u771f\u7684\u6ca1\u90a3\u4e48\u597d\u5199\u2026\u2026\uff09\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6b63\u6587\uff1a<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo sfltool dumpbtm\n\n$ sudo sfltool dumpbtm &gt;~\/dumpbtm.$(date '+%F')\n\n# \u811a\u672c\u7684\u4f7f\u7528\u65b9\u6cd5\n$ chmod u+x .\/sh_parse_dumpbtm_v2.sh\n$ .\/sh_parse_dumpbtm_v2.sh ~\/dumpbtm.2024-04-11 | awk -F'\\t' '{print $1,$2,$3,$NF}'<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># sfltool dumpbtm \u547d\u4ee4\u7684\u8f93\u51fa\u5185\u5bb9\u6837\u4f8b\u5982\u4e0b\n\n========================\n Records for UID -2 : FFFFEEEE-DDDD-CCCC-BBBB-AAAAFFFFFFFE\n========================\n\n ServiceManagement migrated: true\n SharedFileList migrated: false\n\n Items:\n...\n #7:\n                 UUID: E9907828-7AB0-4B5B-985E-57C8B4B6F958\n                 Name: com.xk72.charles.ProxyHelper\n       Developer Name: Charles\n      Team Identifier: 9A5PCU4FSD\n                 Type: curated legacy daemon (0x90010)\n          Disposition: &#91;enabled, disallowed, visible, notified] (9)\n           Identifier: com.xk72.charles.ProxyHelper\n                  URL: file:\/\/\/Library\/LaunchDaemons\/com.xk72.charles.ProxyHelper.plist\n      Executable Path: \/Library\/PrivilegedHelperTools\/com.xk72.charles.ProxyHelper\n           Generation: 18\n    Assoc. Bundle IDs: &#91;com.xk72.Charles ]\n    Parent Identifier: Charles\n...\n\n========================\n Records for UID 0 : FFFFEEEE-DDDD-CCCC-BBBB-AAAA00000000\n========================\n\n ServiceManagement migrated: false\n SharedFileList migrated: false\n\n Items:\n\n #1:\n                 UUID: 7CEC80FD-6488-474B-A782-0E59FB8726A0\n                 Name: (null)\n       Developer Name: (null)\n                 Type: developer (0x20)\n          Disposition: &#91;disabled, allowed, visible, not notified] (2)\n           Identifier: Unknown Developer\n                  URL: (null)\n           Generation: 45\n\n #2:\n                 UUID: 26267948-139D-4480-9633-25054FE1DFC8\n                 Name: Broadcom Inc\n       Developer Name: Broadcom Inc\n                 Type: developer (0x20)\n          Disposition: &#91;disabled, allowed, visible, not notified] (2)\n           Identifier: Broadcom Inc\n                  URL: (null)\n           Generation: 2\n\n #3:\n                 UUID: 7B61DE75-36CA-4B66-AB06-3AA565C54A50\n                 Name: Charles\n       Developer Name: Charles\n                 Type: curated developer (0x80020)\n          Disposition: &#91;disabled, allowed, visible, not notified] (2)\n           Identifier: Charles\n                  URL: (null)\n           Generation: 1\n...\n========================\n Records for UID 501 : FFFFEEEE-00CD-42B1-9BF6-AAAAFFFFFFFE\n========================\n\n ServiceManagement migrated: true\n SharedFileList migrated: true\n\n Items:\n...\n #5:\n                 UUID: 0230D4A4-E37D-42A2-992C-ADF8B390908A\n                 Name: Charles\n       Developer Name: Charles\n                 Type: curated developer (0x80020)\n          Disposition: &#91;disabled, allowed, visible, notified] (10)\n           Identifier: Charles\n                  URL: (null)\n           Generation: 1\n  Embedded Item Identifiers:\n    #1: com.xk72.charles.ProxyHelper\n...<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/zsh\n\n# Usage:\n# .\/sh_parse_dumpbtm_v2.sh ~\/dumpbtm.2024-04-11 | awk -F'\\t' '{print $1,$2,$3,$NF}'\n\n# https:\/\/apple.stackexchange.com\/a\/465945\/100302\n# https:\/\/github.com\/luckman212\/login-items-dump\n\n# sudo sfltool dumpbtm |\n\n# \u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5185\u5bb9\uff0c\u4ee5\u547d\u4ee4\u884c\u4f20\u5165\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u6587\u4ef6\u540d\ncat $1 |\n\/usr\/bin\/awk 'BEGIN { capture=0; u501=0 }\n\nfunction f(field, dv) {\n    if (field &amp;&amp; field != \"(null)\") {\n        return field\n    } else {\n        return (dv==\"\" ? \"-\" : dv)\n    }\n}\n\nfunction fe(field) {\n    if (field &amp;&amp; field != \"(null)\") {\n        return field\n    }\n}\n\n# \u52a0\u5165 u501 \u8fd9\u4e2a\u53d8\u91cf\u662f\u4e3a\u4e86\u7ed9\u53ea\u89e3\u6790\u5f53\u524d\u7528\u6237\u7684\u65e5\u5fd7\u63d0\u4f9b\u4e00\u4e2a\u5f00\u5173\uff0c\u5f53\u8bfb\u53d6\u5230\u90a3\u4e00\u90e8\u5206\u4e86\u4e4b\u540e\u624d\u6253\u5f00\u5f00\u5173\n\/^ Records for UID 501 :\/ { u501=1 }\n\n\/^ #\/ { capture=1; next }\n\/^$\/ { capture=0 }\n\n# capture {\ncapture &amp;&amp; u501 {\n    if (\/Disposition:\/) { status=$NF; disposition=$0; sub(\/^.*Disposition: \/, \"\", disposition) }\n    if (\/Generation:\/) { generation=$2 }\n    if (\/UUID:\/) { uuid=$2 }\n    if (\/URL:\/) { url=$2 }\n    if (\/Type:\/) { type=$0; sub(\/^.*Type: \/, \"\", type) }\n    if (\/^&#91;&#91;:space:]]+Identifier:\/) { identifier=$0; sub(\/^.*Identifier: \/, \"\", identifier) }\n    if (\/Bundle Identifier:\/) { bid=$3 }\n    if (\/Parent Identifier:\/) { pname=$0; sub(\/^.*Parent Identifier: \/, \"\", pname) }\n    if (\/Team Identifier:\/) { tid=$3 }\n    if (\/^&#91;&#91;:space:]]+Name:\/) { name=$0; sub(\/^.*Name: \/, \"\", name) }\n    if (\/Developer Name:\/) { devname=$0; sub(\/^.*Developer Name: \/, \"\", devname) }\n    if (\/Executable Path:\/) { execpath=$0; sub(\/^.*Executable Path: \/, \"\", execpath) }\n}\n\n\/^$\/ {\n    if (fe(name) &amp;&amp; fe(devname)) {\n        cname = sprintf(\"%s (%s)\", name, devname)\n    } else {\n        cname = sprintf(\"%s%s\", fe(name), fe(devname))\n    }\n    if (type ~ \/daemon\/) { cname = \"\ud83d\udc7f\" cname }\n\n    # if (identifier!=\"|\") { printf \"%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\n\", cname, identifier, status, type, pname, f(tid), f(bid), f(url) }\n\n    ue = fe(url) \"|\" fe(execpath)\n    # if (ue!=\"|\" &amp;&amp; a&#91;ue]==\"\") {\n    if (ue!=\"|\" &amp;&amp; a&#91;ue]==\"\" &amp;&amp; status!=\"(2)\") {\n        # printf \"%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\n\", cname, identifier, status, type, pname, f(tid), f(bid), f(url), f(execpath), disposition\n        printf \"%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\n\", cname, identifier, status, type, pname, f(tid), f(bid), f(url), generation\n        a&#91;ue]=1\n    }\n\n    uuid=url=type=bid=tid=name=devname=execpath=cname=identifier=ue=status=pname=disposition=\"\"\n}\n\n# END {for (i in a) print i, a&#91;i]}\n' | \/usr\/bin\/sort -t '\\t' -k2<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n\n\n\n<p>Parse the output of <code>sfltool dumpbtm<\/code><br><a href=\"https:\/\/github.com\/luckman212\/login-items-dump\">https:\/\/github.com\/luckman212\/login-items-dump<\/a><\/p>\n\n\n\n<p>How to determine details of backgound process?<br><a href=\"https:\/\/apple.stackexchange.com\/questions\/465920\/how-to-determine-details-of-backgound-process\">https:\/\/apple.stackexchange.com\/questions\/465920\/how-to-determine-details-of-backgound-process<\/a><\/p>\n\n\n\n<p>awk-\u7528\u4e8e\u5bf9\u6587\u672c\u548c\u6570\u636e\u8fdb\u884c\u5904\u7406\u7684\u7f16\u7a0b\u8bed\u8a00<br><a href=\"https:\/\/wangchujiang.com\/linux-command\/c\/awk.html\">https:\/\/wangchujiang.com\/linux-command\/c\/awk.html<\/a><\/p>\n\n\n\n<p>AWK \u5de5\u4f5c\u539f\u7406<br><a href=\"https:\/\/www.runoob.com\/w3cnote\/awk-work-principle.html\">https:\/\/www.runoob.com\/w3cnote\/awk-work-principle.html<\/a><\/p>\n\n\n\n<p>\u7cbe\u901aawk\u7cfb\u5217<br><a href=\"https:\/\/www.junmajinlong.com\/shell\/awk\/index\/\">https:\/\/www.junmajinlong.com\/shell\/awk\/index\/<\/a><\/p>\n\n\n\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u901a\u8fc7\u5b66\u4e60\u4e00\u4e2a\u7528awk\u5bf9 sfltool dumpbtm \u547d\u4ee4\u8f93\u51fa\u505a\u89e3\u6790\u7684\u6848\u4f8b\u6765\u5b66\u4e60\u4e00\u4e0b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,560,7],"tags":[74,2244,1857,1780,1959],"class_list":["post-5674","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-mac","category-programing","tag-awk","tag-dumpbtm","tag-launchd","tag-macos","tag-sfltool"],"views":1520,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5674","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=5674"}],"version-history":[{"count":1,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5674\/revisions"}],"predecessor-version":[{"id":5675,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5674\/revisions\/5675"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=5674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=5674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=5674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}