{"id":414,"date":"2020-02-04T02:08:44","date_gmt":"2020-02-04T01:08:44","guid":{"rendered":"https:\/\/codedoneright.eu\/?page_id=414"},"modified":"2021-01-01T18:42:22","modified_gmt":"2021-01-01T17:42:22","slug":"running-script","status":"publish","type":"page","link":"https:\/\/codedoneright.eu\/?page_id=414","title":{"rendered":"Running script"},"content":{"rendered":"\n<div style=\"height:56px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>If you have a task that you are performing with any regularity, then you can write a script which will do that for you. The only question is how to do it. I encourage you to grab a book on working with CLI, like this one for example \u2013 <a href=\"https:\/\/www.amazon.com\/Linux-Command-Line-2nd-Introduction\/dp\/1593279523\">The Linux Command Line, 2nd Edition: A Complete Introduction<\/a>. But for now I expect you will be grabbing script from GitHub or other RaspberryPi related sites and wondering how to make it work.<\/p>\n\n\n\n<div style=\"height:56px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Creating script file<\/h4>\n\n\n\n<p class=\"has-text-align-left\">In order to create a script file, create a new file with <em>.sh<\/em> extension, e.g. <em>example_script.sh<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano example_script.sh<\/code><\/pre>\n\n\n\n<p>Each script file needs to start with a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Shebang_(Unix)\">shebang<\/a> \u2013 <em>#!<\/em> after which you specify the shell that will execute the script. Default shell for RaspberryOS and Debian-based distributions is Bash.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash<\/code><\/pre>\n\n\n\n<p>In order to execute the script the file needs execute permissions. Run the following<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chmod +x example_script.sh<\/code><\/pre>\n\n\n\n<p>Example script file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\necho \"Hello world!\"<\/code><\/pre>\n\n\n\n<p>This is a rudimentary script that will display the well-known &#8220;Hello world!&#8221; message in your terminal window.<\/p>\n\n\n\n<div style=\"height:56px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Running script<\/h4>\n\n\n\n<p>In order to execute a script file named <em>example_script.sh<\/em> you just have to type the name prefixing it with <em>.\/<\/em> like so<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/example_script.sh<\/code><\/pre>\n\n\n\n<p>But you have to be in the same directory where the script is located. <\/p>\n\n\n\n<p>If you are in a different directory, instead of prefixing the name with .\/ use the full path to your script, like so<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/path\/to\/script\/example_script.sh<\/code><\/pre>\n\n\n\n<p>After you press ENTER, the script will be executed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have a task that you are performing with any regularity, then you can write a script which will do that for you. The only question is how to do it. I encourage you to grab a book on&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1026,"menu_order":20,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Running script for your daily work with Linux &#8212; Code Done Right!<\/title>\n<meta name=\"description\" content=\"Check out my collection of useful script to help you with your daly use of Linux. Either by scheduling tasks to run automatically or manually!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codedoneright.eu\/?page_id=414\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Running script for your daily work with Linux &#8212; Code Done Right!\" \/>\n<meta name=\"twitter:description\" content=\"Check out my collection of useful script to help you with your daly use of Linux. Either by scheduling tasks to run automatically or manually!\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codedoneright.eu\/?page_id=414\",\"url\":\"https:\/\/codedoneright.eu\/?page_id=414\",\"name\":\"Running script for your daily work with Linux &#8212; Code Done Right!\",\"isPartOf\":{\"@id\":\"https:\/\/codedoneright.eu\/#website\"},\"datePublished\":\"2020-02-04T01:08:44+00:00\",\"dateModified\":\"2021-01-01T17:42:22+00:00\",\"description\":\"Check out my collection of useful script to help you with your daly use of Linux. Either by scheduling tasks to run automatically or manually!\",\"breadcrumb\":{\"@id\":\"https:\/\/codedoneright.eu\/?page_id=414#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codedoneright.eu\/?page_id=414\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codedoneright.eu\/?page_id=414#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/codedoneright.eu\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux\",\"item\":\"https:\/\/codedoneright.eu\/?page_id=1026\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Running script\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codedoneright.eu\/#website\",\"url\":\"https:\/\/codedoneright.eu\/\",\"name\":\"Code Done Right!\",\"description\":\"Raspberry Pi server guides\",\"publisher\":{\"@id\":\"https:\/\/codedoneright.eu\/#\/schema\/person\/50378701e349dbd5d40888bc5b532568\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codedoneright.eu\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/codedoneright.eu\/#\/schema\/person\/50378701e349dbd5d40888bc5b532568\",\"name\":\"CodeDoneRight\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codedoneright.eu\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/codedoneright.eu\/wp-content\/uploads\/www_icon.png\",\"contentUrl\":\"https:\/\/codedoneright.eu\/wp-content\/uploads\/www_icon.png\",\"width\":120,\"height\":120,\"caption\":\"CodeDoneRight\"},\"logo\":{\"@id\":\"https:\/\/codedoneright.eu\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/codedoneright.eu\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Running script for your daily work with Linux &#8212; Code Done Right!","description":"Check out my collection of useful script to help you with your daly use of Linux. Either by scheduling tasks to run automatically or manually!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codedoneright.eu\/?page_id=414","twitter_card":"summary_large_image","twitter_title":"Running script for your daily work with Linux &#8212; Code Done Right!","twitter_description":"Check out my collection of useful script to help you with your daly use of Linux. Either by scheduling tasks to run automatically or manually!","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/codedoneright.eu\/?page_id=414","url":"https:\/\/codedoneright.eu\/?page_id=414","name":"Running script for your daily work with Linux &#8212; Code Done Right!","isPartOf":{"@id":"https:\/\/codedoneright.eu\/#website"},"datePublished":"2020-02-04T01:08:44+00:00","dateModified":"2021-01-01T17:42:22+00:00","description":"Check out my collection of useful script to help you with your daly use of Linux. Either by scheduling tasks to run automatically or manually!","breadcrumb":{"@id":"https:\/\/codedoneright.eu\/?page_id=414#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codedoneright.eu\/?page_id=414"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codedoneright.eu\/?page_id=414#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codedoneright.eu\/"},{"@type":"ListItem","position":2,"name":"Linux","item":"https:\/\/codedoneright.eu\/?page_id=1026"},{"@type":"ListItem","position":3,"name":"Running script"}]},{"@type":"WebSite","@id":"https:\/\/codedoneright.eu\/#website","url":"https:\/\/codedoneright.eu\/","name":"Code Done Right!","description":"Raspberry Pi server guides","publisher":{"@id":"https:\/\/codedoneright.eu\/#\/schema\/person\/50378701e349dbd5d40888bc5b532568"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codedoneright.eu\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/codedoneright.eu\/#\/schema\/person\/50378701e349dbd5d40888bc5b532568","name":"CodeDoneRight","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codedoneright.eu\/#\/schema\/person\/image\/","url":"https:\/\/codedoneright.eu\/wp-content\/uploads\/www_icon.png","contentUrl":"https:\/\/codedoneright.eu\/wp-content\/uploads\/www_icon.png","width":120,"height":120,"caption":"CodeDoneRight"},"logo":{"@id":"https:\/\/codedoneright.eu\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/codedoneright.eu"]}]}},"_links":{"self":[{"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/pages\/414"}],"collection":[{"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codedoneright.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=414"}],"version-history":[{"count":33,"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/pages\/414\/revisions"}],"predecessor-version":[{"id":1419,"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/pages\/414\/revisions\/1419"}],"up":[{"embeddable":true,"href":"https:\/\/codedoneright.eu\/index.php?rest_route=\/wp\/v2\/pages\/1026"}],"wp:attachment":[{"href":"https:\/\/codedoneright.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}