{"id":9410,"date":"2022-04-21T07:00:51","date_gmt":"2022-04-21T07:00:51","guid":{"rendered":"https:\/\/cpanelplesk.com\/wp62\/?p=9410"},"modified":"2022-04-21T07:00:51","modified_gmt":"2022-04-21T07:00:51","slug":"how-to-run-scripts-at-startup","status":"publish","type":"post","link":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/","title":{"rendered":"How to Run Scripts at startup?"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Scripts are required to run upon startup on occasion. It is a good option to automate operations like performing updates, installing packages, or even setting default routes. We&#8217;ll create a new service and run a custom bash script to set static routes in a VPS. Your script can do anything as long as it&#8217;s written in bash and is properly coded. We&#8217;ll start by creating a new service. f2h.service will be the name of our service. Your server can have any name you like, but it must finish in. service.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Because systemd is used to handle services in most Linux distributions, this is a great and simple approach to set up custom functions. Systemd controls startup functions and performs critical tasks such as raising network interfaces. It comes pre-installed in all major OS variants and requires minimal end-user configuration. We&#8217;ll build a new service and write a simple startup script in the next few steps.<\/span><\/p>\n<h3><b>Creating Service<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\/etc\/systemd\/system\/ is where system services are normally found. We&#8217;re utilizing an Ubuntu NVMe VPS, although Debian and CentOS are also viable options. Create a new file with the name of your service and the code.<\/span><\/p>\n<div class=\"command-sh\">\n<pre>nano \/etc\/systemd\/system\/f2h.service\r\n<span style=\"font-weight: 400;\">[Unit]<\/span>\r\n<span style=\"font-weight: 400;\">After=cloud-init.service<\/span>\r\n<span style=\"font-weight: 400;\">[Service]<\/span>\r\n<span style=\"font-weight: 400;\">ExecStart=\/F2H\/routes.sh<\/span>\r\n<span style=\"font-weight: 400;\">[Install]<\/span>\r\n<span style=\"font-weight: 400;\">WantedBy=default.target<\/span>\r\n<\/pre>\n<\/div>\n<p>This section specifies when our custom bash script will be executed. So, after Cloud-init, our script is configured to run. If necessary, you can change this to another service, such as networking. service.<\/p>\n<p><span style=\"font-weight: 400;\">The path to our bash script is called service.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Install = The service&#8217;s installation target. However, this should not be edited.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now chmod the file 664:<\/span><\/p>\n<div class=\"command-sh\">\n<pre>chmod 664 \/etc\/systemd\/system\/f2h.service<\/pre>\n<\/div>\n<h3><strong>Creating Bash Script<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">So, this is the file in which our script will be stored. Our script will be located at \/F2H\/routes.sh, as specified in the service file above.<\/span><\/p>\n<div class=\"command-sh\">\n<pre>nano \/F2H\/routes.sh\r\n<span style=\"font-weight: 400;\">#!\/bin\/bash<\/span>\r\n<span style=\"font-weight: 400;\">ip route add 10.10.10.1 dev eth0<\/span>\r\n<span style=\"font-weight: 400;\">ip route add default via 10.10.10.1<\/span>\r\n<\/pre>\n<\/div>\n<p>A static route to our internal gateway is configured by this script. You have complete control over your script.<\/p>\n<p>Now change the file&#8217;s permissions to 744:<\/p>\n<div class=\"command-sh\">\n<pre>chmod 744 \/F2H\/routes.sh<\/pre>\n<\/div>\n<h3><strong>Reloading Services<\/strong><\/h3>\n<div class=\"command-sh\">\n<pre>systemctl daemon-reload\u00a0\r\n<span style=\"font-weight: 400;\">systemctl enable f2h.service<\/span><\/pre>\n<\/div>\n<p><span style=\"font-weight: 400;\">That is all there is to it. We&#8217;ve constructed a new service and set it to start with a custom bash script.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scripts are required to run upon startup on occasion. It is a good option to automate operations like performing updates, installing packages, or even setting default routes. We&#8217;ll create a new service and run a custom bash script to set static routes in a VPS. Your script can do anything as long as it&#8217;s written [&#8230;]<\/p>\n<p><a class=\"understrap-read-more-link\" href=\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/\">Continue Reading&#8230;<\/a><\/p>\n","protected":false},"author":19,"featured_media":9427,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9410","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpanel"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Run Scripts at startup? - cPanel Plesk<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"How to Run Scripts at startup? - cPanel Plesk\" \/>\n<meta name=\"twitter:description\" content=\"Scripts are required to run upon startup on occasion. It is a good option to automate operations like performing updates, installing packages, or even setting default routes. We&#8217;ll create a new service and run a custom bash script to set static routes in a VPS. Your script can do anything as long as it&#8217;s written [...]Continue Reading...\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2022\/04\/scriptis.png\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"samama\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/\"},\"author\":{\"name\":\"samama\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/b5c17eff2915a029433dfd2d5a6e8465\"},\"headline\":\"How to Run Scripts at startup?\",\"datePublished\":\"2022-04-21T07:00:51+00:00\",\"dateModified\":\"2022-04-21T07:00:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/\"},\"wordCount\":348,\"publisher\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13\"},\"image\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2022\/04\/scriptis.png\",\"articleSection\":[\"Cpanel\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/\",\"url\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/\",\"name\":\"How to Run Scripts at startup? - cPanel Plesk\",\"isPartOf\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2022\/04\/scriptis.png\",\"datePublished\":\"2022-04-21T07:00:51+00:00\",\"dateModified\":\"2022-04-21T07:00:51+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#primaryimage\",\"url\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2022\/04\/scriptis.png\",\"contentUrl\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2022\/04\/scriptis.png\",\"width\":1024,\"height\":538},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cpanelplesk.com\/wp62\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Run Scripts at startup?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#website\",\"url\":\"https:\/\/cpanelplesk.com\/wp62\/\",\"name\":\"cPanel Plesk\",\"description\":\"Blog on famous hosting control panels\",\"publisher\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cpanelplesk.com\/wp62\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13\",\"name\":\"Farooq Omer\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2020\/11\/cpanelplesk.png\",\"contentUrl\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2020\/11\/cpanelplesk.png\",\"width\":300,\"height\":44,\"caption\":\"Farooq Omer\"},\"logo\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/b5c17eff2915a029433dfd2d5a6e8465\",\"name\":\"samama\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5ad71c1d187b45a3c1a68698160b5f6d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5ad71c1d187b45a3c1a68698160b5f6d?s=96&d=mm&r=g\",\"caption\":\"samama\"},\"url\":\"https:\/\/cpanelplesk.com\/wp62\/author\/samama\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Run Scripts at startup? - cPanel Plesk","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:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/","twitter_card":"summary_large_image","twitter_title":"How to Run Scripts at startup? - cPanel Plesk","twitter_description":"Scripts are required to run upon startup on occasion. It is a good option to automate operations like performing updates, installing packages, or even setting default routes. We&#8217;ll create a new service and run a custom bash script to set static routes in a VPS. Your script can do anything as long as it&#8217;s written [...]Continue Reading...","twitter_image":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2022\/04\/scriptis.png","twitter_misc":{"Written by":"samama","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#article","isPartOf":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/"},"author":{"name":"samama","@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/b5c17eff2915a029433dfd2d5a6e8465"},"headline":"How to Run Scripts at startup?","datePublished":"2022-04-21T07:00:51+00:00","dateModified":"2022-04-21T07:00:51+00:00","mainEntityOfPage":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/"},"wordCount":348,"publisher":{"@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13"},"image":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#primaryimage"},"thumbnailUrl":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2022\/04\/scriptis.png","articleSection":["Cpanel"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/","url":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/","name":"How to Run Scripts at startup? - cPanel Plesk","isPartOf":{"@id":"https:\/\/cpanelplesk.com\/wp62\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#primaryimage"},"image":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#primaryimage"},"thumbnailUrl":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2022\/04\/scriptis.png","datePublished":"2022-04-21T07:00:51+00:00","dateModified":"2022-04-21T07:00:51+00:00","breadcrumb":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#primaryimage","url":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2022\/04\/scriptis.png","contentUrl":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2022\/04\/scriptis.png","width":1024,"height":538},{"@type":"BreadcrumbList","@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-run-scripts-at-startup\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cpanelplesk.com\/wp62\/"},{"@type":"ListItem","position":2,"name":"How to Run Scripts at startup?"}]},{"@type":"WebSite","@id":"https:\/\/cpanelplesk.com\/wp62\/#website","url":"https:\/\/cpanelplesk.com\/wp62\/","name":"cPanel Plesk","description":"Blog on famous hosting control panels","publisher":{"@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cpanelplesk.com\/wp62\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13","name":"Farooq Omer","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/image\/","url":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2020\/11\/cpanelplesk.png","contentUrl":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2020\/11\/cpanelplesk.png","width":300,"height":44,"caption":"Farooq Omer"},"logo":{"@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/image\/"}},{"@type":"Person","@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/b5c17eff2915a029433dfd2d5a6e8465","name":"samama","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5ad71c1d187b45a3c1a68698160b5f6d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5ad71c1d187b45a3c1a68698160b5f6d?s=96&d=mm&r=g","caption":"samama"},"url":"https:\/\/cpanelplesk.com\/wp62\/author\/samama\/"}]}},"_links":{"self":[{"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/posts\/9410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/comments?post=9410"}],"version-history":[{"count":3,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/posts\/9410\/revisions"}],"predecessor-version":[{"id":9437,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/posts\/9410\/revisions\/9437"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/media\/9427"}],"wp:attachment":[{"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/media?parent=9410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/categories?post=9410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/tags?post=9410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}