{"id":1601,"date":"2011-09-22T11:14:28","date_gmt":"2011-09-22T16:14:28","guid":{"rendered":"http:\/\/icesquare.com\/wordpress\/?p=1601"},"modified":"2012-08-14T18:07:33","modified_gmt":"2012-08-14T23:07:33","slug":"freebsd-startup-script-how-to-start-a-script-on-boot-in-freebsd","status":"publish","type":"post","link":"https:\/\/icesquare.com\/wordpress\/freebsd-startup-script-how-to-start-a-script-on-boot-in-freebsd\/","title":{"rendered":"FreeBSD Startup Script &#8211; How to Start a Script on Boot in FreeBSD (An Alternative Solution to \/etc\/rc.local)"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/wordpress\/wp-content\/uploads\/2011\/09\/FreeBSDIcon.png\" alt=\"\" title=\"FreeBSD\" class=\"alignleft size-full\" \/><\/p>\n<p style=\"margin-bottom:50px;\">I want to start a script when booting my FreeBSD box automatically. Unlike Linux, FreeBSD does not honor the script you put in \/etc\/rc.local. Usually it is recommended to use the rc service (See <a href=\"http:\/\/www.freebsd.org\/doc\/handbook\/configtuning-starting-services.html\" target=\"_blank\">here<\/a> for details), however I think it is too complicated to convert my script to a rc compatible version. I decide to explore more simple solutions. I found that it can be done via Cron.<\/p>\n<p style=\"margin:20px;\">\n<p>Suppose I have a script in the following location. I decide to run it when booting the machine automatically:<\/p>\n<pre>\r\n\/script\/myscript.sh\r\n<\/pre>\n<p>First, I need to include this script in the Cron:<\/p>\n<pre>\r\nsudo nano \/etc\/crontab\r\n<\/pre>\n<p>And add the following to the end of the file:<\/p>\n<pre>\r\n@reboot root \/script\/myscript.sh\r\n<\/pre>\n<p>That will make the system to execute this script. <\/p>\n<p>However, the system may not run your script correctly because the Cron job uses a different shell and the path information may be missing. You can fix it by modifying the SHELL and PATH variables in \/etc\/crontab:<\/p>\n<p>In my case, I uses Bash and I like my script executed by Bash:<\/p>\n<pre>\r\nSHELL=\/usr\/local\/bin\/bash\r\n<\/pre>\n<p>And my script needs to execute some commands that locate in \/usr\/local\/bin:<\/p>\n<pre>\r\nPATH=\/etc:\/bin:\/sbin:\/usr\/bin:\/usr\/sbin:\/usr\/local\/bin\r\n<\/pre>\n<p>That&#8217;s it! Have fun with FreeBSD.<\/p>\n<p>&#8211;Derrick<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want to start a script when booting my FreeBSD box automatically. Unlike Linux, FreeBSD does not honor the script you put in \/etc\/rc.local. Usually it is recommended to use <a class=\"more-link\" href=\"https:\/\/icesquare.com\/wordpress\/freebsd-startup-script-how-to-start-a-script-on-boot-in-freebsd\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[94,7,144,6,69],"tags":[126,171],"class_list":["post-1601","post","type-post","status-publish","format-standard","hentry","category-computer-problems-computer-help-pc-support","category-freebsd","category-sever-problem","category-technology","category-troubleshooting-technology","tag-cron-job","tag-freebsd"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p1sqzr-pP","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2122,"url":"https:\/\/icesquare.com\/wordpress\/delete-empty-system-mail-box-freebsd-linux\/","url_meta":{"origin":1601,"position":0},"title":"How to Delete System Mail \/ Empty System Mail box in FreeBSD \/ Linux?","author":"Derrick","date":"December 22, 2011","format":false,"excerpt":"[ad#adbrite] When I checked my FreeBSD system mail box today, I found that there were 8000 system mails sitting my mail box: mail Mail version 8.1 6\/6\/93. Type ? for help. \"\/var\/mail\/root\": 8182 messages 8182 new >N 1 root@localhost.my.do Fri Sep 30 03:02 44\/1330 \"x.com output\" N 2 root@localhost.my.do Fri\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":900,"url":"https:\/\/icesquare.com\/wordpress\/cannot-find-autoconf-please-check-your-autoconf-installation-and-the-php_autoconf-environment-variable-then-rerun-this-script\/","url_meta":{"origin":1601,"position":1},"title":"Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.","author":"Derrick","date":"October 22, 2010","format":false,"excerpt":"This post is about FreeBSD, however the idea is about the same for other Unix systems. While I tried to install memcached, the system complained with this message: Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. This problem is caused by\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1591,"url":"https:\/\/icesquare.com\/wordpress\/the-develautomake110-port-has-been-deleted-no-longer-required-by-any-port-aborting-update\/","url_meta":{"origin":1601,"position":2},"title":"The devel\/automake110 port has been deleted: No longer required by any port&#8230;Aborting update","author":"Derrick","date":"September 21, 2011","format":false,"excerpt":"My FreeBSD box must be sick today. For some reasons, when I ran the portsnap command (i.e., portsnap fetch update), it removed the entire port directory (i.e., rm \/usr\/ports -Rf). Therefore, I decided to build the entire port tree: sudo su cd \/var\/db\/portsnap rm -Rf * portsnap fetch extract I\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1919,"url":"https:\/\/icesquare.com\/wordpress\/fedora-16-etc-rc-local\/","url_meta":{"origin":1601,"position":3},"title":"[Solved]Fedora 16 \/etc\/rc.local is missing","author":"Derrick","date":"November 29, 2011","format":false,"excerpt":"Finally, I got a chance to try the new Fedora 16. The overall experience is pretty good, except that it comes with some troublesomes. I guess it is a bonus feature to test your troubleshooting skills. No problem, those are piece of cake to me. After trying for about 15\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"\/wordpress\/wp-content\/uploads\/2011\/08\/fedora-logo-150x150.png","width":350,"height":200},"classes":[]},{"id":3002,"url":"https:\/\/icesquare.com\/wordpress\/freebsd-org-was-compromised\/","url_meta":{"origin":1601,"position":4},"title":"FreeBSD.org Was Compromised. What Should You Do Next?","author":"Derrick","date":"November 17, 2012","format":false,"excerpt":"In case you are not aware this bad news. FreeBSD.org was compromised on September 17, 2012. Good news is that the compromise was caused by a human error (a stupid developer leaked a SSH private key somewhere), which has nothing to do with the code quality of the FreeBSD. :-)\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3295,"url":"https:\/\/icesquare.com\/wordpress\/freebsdproblem-to-update-curl-7-31-0\/","url_meta":{"origin":1601,"position":5},"title":"[FreeBSD]Problem to Update cURL-7.31.0","author":"Derrick","date":"August 6, 2013","format":false,"excerpt":"When I tried to update the cURL to cURL 7.31.0 today for my FreeBSD, it stopped and gave the following error messages: configure: using CFLAGS: -O2 -pipe -DLDAP_DEPRECATED -fno-strict-aliasing configure: CFLAGS error: CFLAGS may only be used to specify C compiler flags, not macro definitions. Use CPPFLAGS for: -DLDAP_DEPRECATED configure:\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/1601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1601"}],"version-history":[{"count":17,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/1601\/revisions"}],"predecessor-version":[{"id":2865,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/1601\/revisions\/2865"}],"wp:attachment":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}