{"id":90088,"date":"2024-03-02T06:05:15","date_gmt":"2024-03-01T22:05:15","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=90088"},"modified":"2024-03-02T06:05:15","modified_gmt":"2024-03-01T22:05:15","slug":"automatic-running-methods","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/automatic-running-methods.html","title":{"rendered":"Linux\u7cfb\u7edf\u4e2d\u8bbe\u7f6e\u5f00\u673a\u81ea\u52a8\u8fd0\u884c\u7684\u4e24\u79cd\u65b9\u6cd5"},"content":{"rendered":"

\u6709\u65f6\u53ef\u80fd\u4f1a\u9700\u8981\u5728\u91cd\u542f\u65f6\u6216\u8005\u6bcf\u6b21\u7cfb\u7edf\u542f\u52a8\u65f6\u8fd0\u884c\u67d0\u4e9b\u547d\u4ee4\u6216\u8005\u811a\u672c\u3002\u6211\u4eec\u8981\u600e\u6837\u505a\u5462\uff1f\u672c\u6587\u4e2d\u6211\u4eec\u5c31\u5bf9\u6b64\u8fdb\u884c\u8ba8\u8bba\u3002 \u6211\u4eec\u4f1a\u7528\u4e24\u79cd\u65b9\u6cd5\u6765\u63cf\u8ff0\u5982\u4f55\u5728 CentOS\/RHEL \u4ee5\u53ca Ubuntu \u7cfb\u7edf\u4e0a\u505a\u5230\u91cd\u542f\u6216\u8005\u7cfb\u7edf\u542f\u52a8\u65f6\u6267\u884c\u547d\u4ee4\u548c\u811a\u672c\u3002 \u4e24\u79cd\u65b9\u6cd5\u90fd\u901a\u8fc7\u4e86\u6d4b\u8bd5\u3002<\/p>\n

\"\"<\/p>\n

\u65b9\u6cd5 1 \u2013 \u4f7f\u7528 rc.local<\/strong><\/div>\n

\u8fd9\u79cd\u65b9\u6cd5\u4f1a\u5229\u7528 \/etc\/ \u4e2d\u7684 rc.local \u6587\u4ef6\u6765\u5728\u542f\u52a8\u65f6\u6267\u884c\u811a\u672c\u4e0e\u547d\u4ee4\u3002\u6211\u4eec\u5728\u6587\u4ef6\u4e2d\u52a0\u4e0a\u4e00\u884c\u6765\u6267\u884c\u811a\u672c\uff0c\u8fd9\u6837\u6bcf\u6b21\u542f\u52a8\u7cfb\u7edf\u65f6\uff0c\u90fd\u4f1a\u6267\u884c\u8be5\u811a\u672c\u3002<\/p>\n

\u4e0d\u8fc7\u6211\u4eec\u9996\u5148\u9700\u8981\u4e3a \/etc\/rc.local \u6dfb\u52a0\u6267\u884c\u6743\u9650\uff0c<\/p>\n

$ sudo chmod +x \/etc\/rc.local<\/pre>\n

\u7136\u540e\u5c06\u8981\u6267\u884c\u7684\u811a\u672c\u52a0\u5165\u5176\u4e2d\uff1a<\/p>\n

$ sudo vi \/etc\/rc.local<\/pre>\n

\u5728\u6587\u4ef6\u6700\u540e\u52a0\u4e0a\uff1a<\/p>\n

sh \/root\/script.sh &<\/pre>\n

\u7136\u540e\u4fdd\u5b58\u6587\u4ef6\u5e76\u9000\u51fa\u3002\u4f7f\u7528 rc.local \u6587\u4ef6\u6765\u6267\u884c\u547d\u4ee4\u4e5f\u662f\u4e00\u6837\u7684\uff0c\u4f46\u662f\u4e00\u5b9a\u8981\u8bb0\u5f97\u586b\u5199\u547d\u4ee4\u7684\u5b8c\u6574\u8def\u5f84\u3002 \u60f3\u77e5\u9053\u547d\u4ee4\u7684\u5b8c\u6574\u8def\u5f84\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n

$ which command<\/pre>\n

\u6bd4\u5982\uff1a<\/p>\n

$ which shutter\r\n\/usr\/bin\/shutter<\/pre>\n

\u5982\u679c\u662f CentOS\uff0c\u6211\u4eec\u4fee\u6539\u7684\u662f\u6587\u4ef6 \/etc\/rc.d\/rc.local \u800c\u4e0d\u662f \/etc\/rc.local\u3002 \u4e0d\u8fc7\u6211\u4eec\u4e5f\u9700\u8981\u5148\u4e3a\u8be5\u6587\u4ef6\u6dfb\u52a0\u53ef\u6267\u884c\u6743\u9650\u3002<\/p>\n

\u6ce8\u610f:- \u542f\u52a8\u65f6\u6267\u884c\u7684\u811a\u672c\uff0c\u8bf7\u4e00\u5b9a\u4fdd\u8bc1\u662f\u4ee5 exit 0 \u7ed3\u5c3e\u7684\u3002<\/p>\n

\u65b9\u6cd5 2 \u2013 \u4f7f\u7528 Crontab<\/strong><\/div>\n

\u8be5\u65b9\u6cd5\u6700\u7b80\u5355\u4e86\u3002\u6211\u4eec\u521b\u5efa\u4e00\u4e2a cron \u4efb\u52a1\uff0c\u8fd9\u4e2a\u4efb\u52a1\u5728\u7cfb\u7edf\u542f\u52a8\u540e\u7b49\u5f85 90 \u79d2\uff0c\u7136\u540e\u6267\u884c\u547d\u4ee4\u548c\u811a\u672c\u3002<\/p>\n

\u8981\u521b\u5efa cron \u4efb\u52a1\uff0c\u6253\u5f00\u7ec8\u7aef\u5e76\u6267\u884c<\/p>\n

$ crontab -e<\/pre>\n

\u7136\u540e\u8f93\u5165\u4e0b\u884c\u5185\u5bb9\uff0c<\/p>\n

@reboot ( sleep 90 ; sh \\location\\script.sh )<\/pre>\n

\u8fd9\u91cc \\location\\script.sh \u5c31\u662f\u5f85\u6267\u884c\u811a\u672c\u7684\u5730\u5740\u3002<\/p>\n

\u6211\u4eec\u7684\u6587\u7ae0\u81f3\u6b64\u5c31\u5b8c\u4e86\u3002\u5982\u6709\u7591\u95ee\uff0c\u6b22\u8fce\u7559\u8a00\u3002<\/p>\n

via: http:\/\/linuxtechlab.com\/executing-commands-scripts-at-reboot\/<\/p>\n

\u4f5c\u8005\uff1aShusain \u8bd1\u8005\uff1alujun9972 \u6821\u5bf9\uff1awxy<\/p>\n

\u672c\u6587\u7531 LCTT \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd \u8363\u8a89\u63a8\u51fa<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-9123-1.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/automatic-running-methods.html<\/a>\u7f16\u8f91\uff1a\u6e05\u84b8github\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u6709\u65f6\u53ef\u80fd\u4f1a\u9700\u8981\u5728\u91cd\u542f\u65f6\u6216\u8005\u6bcf\u6b21\u7cfb\u7edf\u542f\u52a8\u65f6\u8fd0\u884c\u67d0\u4e9b\u547d\u4ee4\u6216\u8005\u811a\u672c\u3002\u6211\u4eec\u8981\u600e\u6837\u505a\u5462\uff1f\u672c\u6587\u4e2d\u6211\u4eec\u5c31\u5bf9\u6b64\u8fdb\u884c\u8ba8\u8bba\u3002 \u6211\u4eec […]<\/p>\n","protected":false},"author":317,"featured_media":90090,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-90088","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/90088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/317"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=90088"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/90088\/revisions"}],"predecessor-version":[{"id":290217,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/90088\/revisions\/290217"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/90090"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=90088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=90088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=90088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}