{"id":390,"date":"2009-06-21T10:04:05","date_gmt":"2009-06-21T08:04:05","guid":{"rendered":"http:\/\/raftaman.net\/?p=390"},"modified":"2021-05-15T11:46:42","modified_gmt":"2021-05-15T09:46:42","slug":"running-a-script-on-shutdown","status":"publish","type":"post","link":"https:\/\/possiblelossofprecision.net\/?p=390","title":{"rendered":"Running a script on shutdown"},"content":{"rendered":"<p>It&#8217;s rather easy to run a command or a script on boot without going through the full <a href=\"http:\/\/en.wikipedia.org\/wiki\/UNIX_System_V\">Sys V<\/a> style init stuff. <code>\/etc\/rc.local<\/code> is executed after the init scripts on boot, but unlike BSD, Linux doesn&#8217;t have a <code>rc.shutdown<\/code>.<\/p>\n<p>So how can we execute a command on shutdown? Usually, <code>\/etc\/init.d\/halt<\/code> is used for shutting down, which calls <code>\/sbin\/halt.local<\/code> (if it exists). So we simply add our commands to <code>\/sbin\/halt.local<\/code>:<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">\r\n# echo &quot;YOUR_COMMAND&quot; &gt;&gt; \/sbin\/halt.local\r\n<\/pre>\n<p>Note that if the file does not exist, you have to add a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Shebang_%28Unix%29\">shebang<\/a> (e.g. <code>#!\/bin\/sh<\/code>) and make it executable (<code>chmod +x \/sbin\/halt.local<\/code>)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s rather easy to run a command or a script on boot without going through the full Sys V style init stuff. \/etc\/rc.local is executed after the init scripts on boot, but unlike BSD, Linux doesn&#8217;t have a rc.shutdown. So how can we execute a command on shutdown? Usually, \/etc\/init.d\/halt is used for shutting down, which calls \/sbin\/halt.local (if it&#8230; <a href=\"https:\/\/possiblelossofprecision.net\/?p=390\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[13,7],"class_list":["post-390","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-centos","tag-fedora"],"_links":{"self":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=390"}],"version-history":[{"count":5,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/390\/revisions"}],"predecessor-version":[{"id":2700,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/390\/revisions\/2700"}],"wp:attachment":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}