{"id":139,"date":"2019-01-16T11:22:09","date_gmt":"2019-01-16T07:22:09","guid":{"rendered":"http:\/\/kidds.co.za\/?p=139"},"modified":"2019-01-16T11:22:30","modified_gmt":"2019-01-16T07:22:30","slug":"run-scripts-after-machine-has-rebooted","status":"publish","type":"post","link":"https:\/\/kidds.co.za\/index.php\/2019\/01\/16\/run-scripts-after-machine-has-rebooted\/","title":{"rendered":"Run scripts after machine has rebooted"},"content":{"rendered":"\n<p>Create an @reboot entry in your crontab to run a script called \/usr\/local\/bin\/runonce.<\/p>\n\n\n\n<p>Create a directory structure called \/etc\/local\/runonce.d\/ran using mkdir -p.<\/p>\n\n\n\n<p>Create the script \/usr\/local\/bin\/runonce as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    #!\/bin\/sh\nfor file in \/etc\/local\/runonce.d\/*\ndo\n    if [ ! -f \"$file\" ]\n    then\n        continue\n    fi\n    \"$file\"\n    mv \"$file\" \"\/etc\/local\/runonce.d\/ran\/$file.$(date +%Y%m%dT%H%M%S)\"\n    logger -t runonce -p local3.info \"$file\"\ndone<\/code><\/pre>\n\n\n\n<p>Now place any script you want run at the next reboot (once only) in the directory \/etc\/local\/runonce.d and chown and chmod +x it appropriately. Once it&#8217;s been run, you&#8217;ll find it moved to the ran subdirectory and the date and time appended to its name. There will also be an entry in your syslog<\/p>\n\n\n\n<p>Credit is to Dennis Williams&nbsp;<a href=\"https:\/\/serverfault.com\/questions\/148341\/linux-schedule-command-to-run-once-after-reboot-runonce-equivalent\">https:\/\/serverfault.com\/questions\/148341\/linux-schedule-command-to-run-once-after-reboot-runonce-equivalent<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create an @reboot entry in your crontab to run a script called \/usr\/local\/bin\/runonce. Create a directory structure called \/etc\/local\/runonce.d\/ran using mkdir -p. Create the script \/usr\/local\/bin\/runonce as follows: Now place any script you want run at the next reboot (once only) in the directory \/etc\/local\/runonce.d and chown and chmod +x it appropriately. Once it&#8217;s been [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,2],"tags":[],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-general-server-stuff","category-linux"],"_links":{"self":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":1,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":140,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/139\/revisions\/140"}],"wp:attachment":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}