{"id":1607,"date":"2020-07-24T10:05:36","date_gmt":"2020-07-24T02:05:36","guid":{"rendered":"http:\/\/iqotom.com\/?p=1607"},"modified":"2020-07-24T10:05:38","modified_gmt":"2020-07-24T02:05:38","slug":"liunx%e5%bc%80%e6%9c%ba%e8%87%aa%e5%90%af%e5%8a%a8%e8%84%9a%e6%9c%ac%e7%9a%84%e5%87%a0%e7%a7%8d%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/iqotom.com\/?p=1607","title":{"rendered":"Liunx\u5f00\u673a\u81ea\u542f\u52a8\u811a\u672c\u7684\u51e0\u79cd\u65b9\u6cd5"},"content":{"rendered":"\n<p style=\"font-size:18px\">\u3000\u3000\u6211\u4eec\u5e38\u5728windows\u4e0a\u5f00\u673a\u81ea\u52a8\u542f\u52a8\u4e00\u4e9b\u7a0b\u5e8f\uff0c\u4f46liunx\u5927\u591a\u4f1a\u662f\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u6211\u4eec\u4f1a\u6dfb\u52a0\u4e9b\u542f\u52a8\u7684\u811a\u672c\u6765\u542f\u52a8\u5b83\u3002\u90a3\u4e48liunx\u4e0a\u91cd\u542f\u540e\u81ea\u52a8\u542f\u884c\u7a0b\u5e8f\u662f\u600e\u4e48\u5b9e\u73b0\u7684\u3002\u90a3\u4e48\u6211\u4eec\u4ecb\u7ecd\u5982\u4e0b\u7684\u4e09\u79cd\u65b9\u6cd5\uff0c\u975e\u5e38\u5b9e\u7528\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u4fee\u6539\/etc\/rc.d\/rc.local\u6587\u4ef6<\/h2>\n\n\n\n<p><code>\/etc\/rc.d\/rc.local<\/code>\u00a0\u6587\u4ef6\u4f1a\u5728 Linux \u7cfb\u7edf\u5404\u9879\u670d\u52a1\u90fd\u542f\u52a8\u5b8c\u6bd5\u4e4b\u540e\u518d\u88ab\u8fd0\u884c\u3002\u6240\u4ee5\u4f60\u60f3\u8981\u81ea\u5df1\u7684\u811a\u672c\u5728\u5f00\u673a\u540e\u88ab\u8fd0\u884c\u7684\u8bdd\uff0c\u53ef\u4ee5\u5c06\u81ea\u5df1\u811a\u672c\u8def\u5f84\u52a0\u5230\u8be5\u6587\u4ef6\u91cc\u3002 <\/p>\n\n\n\n<p>\u5148\u786e\u4fdd\u6743\u9650<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$ chmod +x \/etc\/rc.d\/rc.local<\/code><\/pre>\n\n\n\n<p>\u6f14\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$ vim auto_run_script.sh\n\n#!\/bin\/bash\ndate >> \/home\/alvin\/output.txt\nhostname >> \/home\/alvin\/output.txt<\/code><\/pre>\n\n\n\n<p> \u4fdd\u5b58\u9000\u51fa\u540e\uff0c\u8d4b\u4e88\u53ef\u6267\u884c\u6743\u9650 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$ chmod +x auto_run_script.sh<\/code><\/pre>\n\n\n\n<p>\u6dfb\u52a0\u5230<code>rc.local<\/code>\u6587\u4ef6\u672b\u5c3e\uff0c\u7136\u540e\u91cd\u542f<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upload-images.jianshu.io\/upload_images\/13303086-038fc4a996ef9d59?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/331\/format\/webp\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u4f7f\u7528crontab<\/h2>\n\n\n\n<p> crontab \u662f Linux \u4e0b\u7684\u8ba1\u5212\u4efb\u52a1\uff0c\u5f53\u65f6\u95f4\u8fbe\u5230\u6211\u4eec\u8bbe\u5b9a\u7684\u65f6\u95f4\u65f6\uff0c\u53ef\u4ee5\u81ea\u52a8\u89e6\u53d1\u67d0\u4e9b\u811a\u672c\u7684\u8fd0\u884c\u3002 <\/p>\n\n\n\n<p>\n\n\u6211\u4eec\u53ef\u4ee5\u81ea\u5df1\u8bbe\u7f6e\u8ba1\u5212\u4efb\u52a1\u65f6\u95f4\uff0c\u7136\u540e\u7f16\u5199\u5bf9\u5e94\u7684\u811a\u672c\u3002\u4f46\u662f\uff0c\u6709\u4e2a\u7279\u6b8a\u7684\u4efb\u52a1\uff0c\u53eb\u4f5c&nbsp;<code>@reboot<\/code>&nbsp;\uff0c\u6211\u4eec\u5176\u5b9e\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4ece\u5b83\u7684\u5b57\u9762\u610f\u4e49\u770b\u51fa\u6765\uff0c\u8fd9\u4e2a\u4efb\u52a1\u5c31\u662f\u5728\u7cfb\u7edf\u91cd\u542f\u4e4b\u540e\u81ea\u52a8\u8fd0\u884c\u67d0\u4e2a\u811a\u672c\u3002\n\n<\/p>\n\n\n\n<p>\u6f14\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$ crontab -e\n\n@reboot \/home\/alvin\/auto_run_script.sh<\/code><\/pre>\n\n\n\n<p>\n\n\u7136\u540e\uff0c\u76f4\u63a5\u91cd\u542f\u5373\u53ef\u3002\u8fd0\u884c\u7684\u6548\u679c\u8ddf\u4e0a\u9762\u7c7b\u4f3c\u3002\n\n<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001 \u4f7f\u7528 systemd \u670d\u52a1 <\/h2>\n\n\n\n<p> \u4ee5\u4e0a\u4ecb\u7ecd\u7684\u4e24\u79cd\u65b9\u6cd5\uff0c\u5728\u4efb\u4f55 Linux \u7cfb\u7edf\u4e0a\u90fd\u53ef\u4ee5\u4f7f\u7528\u3002\u4f46\u672c\u65b9\u6cd5\u4ec5\u9002\u7528\u4e8e systemd \u7cfb\u7edf\u3002\u5982\u4f55\u533a\u5206\u662f\u4e0d\u662f systemd \u7cfb\u7edf\uff1f\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u8fd0\u884c <code>ps aux<\/code> \u547d\u4ee4\uff0c\u67e5\u770b pid \u4e3a 1 \u7684\u8fdb\u7a0b\u662f\u4e0d\u662f systemd \u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upload-images.jianshu.io\/upload_images\/13303086-bbc479d16f85ae47?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/1057\/format\/webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u4e3a\u4e86\u5b9e\u73b0\u76ee\u7684\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a systemd \u542f\u52a8\u670d\u52a1\uff0c\u5e76\u628a\u5b83\u653e\u7f6e\u5728 <code>\/etc\/systemd\/system\/<\/code> \u76ee\u5f55\u4e0b\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u521b\u5efa\u7684 systemd \u542f\u52a8\u670d\u52a1\u5982\u4e0b\u3002\u8bf7\u6ce8\u610f\uff0c\u8fd9\u65f6\u540e\u7f00\u662f <code>.service<\/code> \uff0c\u800c\u4e0d\u662f <code>.sh<\/code> \u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$ vim auto_run_script.service\n\n[Unit]\nDescription=Run a Custom Script at Startup\nAfter=default.target\n\n[Service]\nExecStart=\/home\/alvin\/auto_run_script.sh\n\n[Install]\nWantedBy=default.target<\/code><\/pre>\n\n\n\n<p> \u4ece\u670d\u52a1\u7684\u5185\u5bb9\u53ef\u4ee5\u770b\u51fa\u6765\uff0c\u6211\u4eec\u6700\u7ec8\u8fd8\u662f\u4f1a\u8c03\u7528 <code>\/home\/alvin\/auto_run_script.sh<\/code> \u8fd9\u4e2a\u811a\u672c\u3002 <\/p>\n\n\n\n<p>\n\n\u7136\u540e\uff0c\u6211\u4eec\u518d\u628a\u8fd9\u4e2a\u811a\u672c\u653e\u7f6e\u5728&nbsp;<code>\/etc\/systemd\/systerm\/<\/code>&nbsp;\u76ee\u5f55\u4e0b\uff0c\u4e4b\u540e\u6211\u4eec\u518d\u8fd0\u884c\u4e0b\u9762\u4e24\u6761\u547d\u4ee4\u6765\u66f4\u65b0 systemd \u914d\u7f6e\u6587\u4ef6\uff0c\u5e76\u542f\u52a8\u670d\u52a1\u3002\n\n<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$ systemctl daemon-reload\n$ systemctl enable auto_run_script.service<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\u91cd\u542f\u7cfb\u7edf\u3002 <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u8f6c\u8f7d\u94fe\u63a5\uff1ahttps:\/\/www.jianshu.com\/p\/80f4c90cb109<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u3000\u6211\u4eec\u5e38\u5728windows\u4e0a\u5f00\u673a\u81ea\u52a8\u542f\u52a8\u4e00\u4e9b\u7a0b\u5e8f\uff0c\u4f46liunx\u5927\u591a\u4f1a\u662f\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u6211\u4eec\u4f1a\u6dfb\u52a0\u4e9b\u542f\u52a8\u7684\u811a\u672c\u6765\u542f\u52a8\u2026 <span class=\"read-more\"><a href=\"http:\/\/iqotom.com\/?p=1607\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":169,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[7],"_links":{"self":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/1607"}],"collection":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1607"}],"version-history":[{"count":3,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/1607\/revisions"}],"predecessor-version":[{"id":1610,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/1607\/revisions\/1610"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/media\/169"}],"wp:attachment":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1607"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}