{"id":687,"date":"2012-10-20T12:49:57","date_gmt":"2012-10-20T12:49:57","guid":{"rendered":"https:\/\/raspberry-projects.com\/pi\/?p=687"},"modified":"2014-09-26T15:05:28","modified_gmt":"2014-09-26T15:05:28","slug":"scripts","status":"publish","type":"post","link":"https:\/\/raspberry-projects.com\/pi\/pi-operating-systems\/raspbian\/scripts","title":{"rendered":"Scripts"},"content":{"rendered":"<h4>\nAuto running a script<br \/>\n<\/h4>\n<h5>\nCreate the script<br \/>\n<\/h5>\n<p>\nCreate a folder to store the script in\n<\/p>\n<pre>\r\n<code>\r\nmkdir .\/bin\r\ncd .\/bin\r\n<\/code><\/pre>\n<p>\nCreate the script using the nano text editor\n<\/p>\n<pre>\r\n<code>\r\nsudo nano script_auto_run\r\n<\/code><\/pre>\n<p>\nIn the nano editor, type this script:\n<\/p>\n<pre>\r\n<code>\r\n#!\/bin\/bash\r\n# Script to start our application\r\necho &quot;Doing autorun script...&quot;\r\nsudo \/home\/pi\/projects\/my_project.a &amp;\r\n&nbsp;<\/code><\/pre>\n<p>\nReplace &quot;sudo \/home\/pi\/projects\/my_project.a &amp;&quot; with the commands you want carried out. &nbsp;The &quot;&amp;&quot; means do the command in the background.\n<\/p>\n<p>\nNote that when executing a command without logging is as a user you can&#39;t depend on any path or environment variables so you must provide full paths to everything.\n<\/p>\n<p>\nSave it by pressing Ctrl+X, &quot; Y&quot;, ENTER\n<\/p>\n<p>\nThis script needs to be made executable by typing this :\n<\/p>\n<pre>\r\n<code>\r\nsudo chmod 755 script_auto_run\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\nYou can test the script works by typing\n<\/p>\n<pre>\r\n<code>\r\n\/home\/pi\/bin\/script_auto_run\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<h5>\nSetting it to be run<br \/>\n<\/h5>\n<p>\nTo launch the script at start-up edit the &ldquo;rc.local&rdquo; file needs to be edited.\n<\/p>\n<pre>\r\n<code>\r\nsudo nano \/etc\/rc.local\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\nAdd the following line:\n<\/p>\n<pre>\r\n<code>\r\n\/home\/pi\/bin\/script_auto_run\r\n<\/code><\/pre>\n<p>\nSave it by pressing Ctrl+X, &quot; Y&quot;, ENTER\n<\/p>\n<p>\nRe-boot your RPi and it will run.\n<\/p>\n<h4>\nSolving Issues<br \/>\n<\/h4>\n<p>\nrc.local runs&nbsp;as root user which might cause problems for some actions you perform in scripts. You may also want a slight delay before a script is executed. &nbsp;There&#39;s solutions to both of these issues <a href=\"https:\/\/raspberry-projects.com\/pi\/pi-operating-systems\/raspbian\/auto-running-programs\">here<\/a>.\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Auto running a script Create the script Create a folder to store the script in mkdir .\/bin cd .\/bin Create the script using the nano text editor sudo nano script_auto_run In the nano editor, type this script: #!\/bin\/bash # Script to start our application echo &quot;Doing autorun script&#8230;&quot; sudo \/home\/pi\/projects\/my_project.a &amp; &nbsp; Replace &quot;sudo \/home\/pi\/projects\/my_project.a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-687","post","type-post","status-publish","format-standard","hentry","category-raspbian"],"_links":{"self":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/comments?post=687"}],"version-history":[{"count":4,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/687\/revisions"}],"predecessor-version":[{"id":1531,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/687\/revisions\/1531"}],"wp:attachment":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/media?parent=687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/categories?post=687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/tags?post=687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}