How to Auto Execute Commands/Scripts During Reboot or Startup

...

15 javascript7 code5 blog5 snippet4 github4 tutorial3 nlp2 api2 web development2 web2 php2 jquery2 css2 natural language generation2 uvloop1 butterflynet1 morepath1 encryption1 ssl1 technology1 google maps1 markers1 eve1 app1 twig1 nodeJS1 sailsJS1 venngage1 freebbble1 top1 artificial intelligence1 process1 google wallet1 wireframing1 speed1 cdn1 sanic1 queries1 handlebars1 helpers1 js1 zoho1 ticket tracking1 issue tracking1 less1 mixins1 site1 philleepedit.1 year1 new1 view1 bug tracking1 bugs1 grid1 search engine optimization1 range selectors1 lucidpress1 plugins1 mod1 graphic design1 copywriting1 tutorials1 sql1 nodejs1 tools1 social media marketing1 https1 lucidchart1 vuejs1 angularjs1 reactjs1 fullscreen1 chrome1 android1 polymerjs1 aurelia.io1 macos tips1 npm1 law1 AI1 wikihow1 nonchalant1 safari1 youtube1 socket.io1 meteor1 express.js1 node.js1 app development1 progressive web apps1 keystone1 koa.js1 broccoli1 webpack1 babel1 electrode.js1 pm21 node1 nginx1 form1 design1 smashing magazine1 user experience1 database1 d3.js1 html design1 underscore1 google slides1 pexels1 pitcherific1 es51 lodash1 ecmascript1 json1 mysql1 learning1 intelligent1 html1 open source1 Apache1 education1 intelligence1 IQ1 web31 web intelligence1 happiness1 money1 smarts1 awesome screenshot1

Steven Hansen

Are You Trying to Become a Programmer? – Hacker Noon

alistapart.com

Progressive Web Apps: The Case for PWAs

Using CSS Mod Queries with Range Selectors

David Power

Why desktop apps are coming back – Hiri

techcrunch.com

Google’s Flutter toolkit goes beyond mobile with Project Hummingbird

Eric Elliott

Native Apps are Doomed!

workingmouse.com.au

Progressive Web Apps Are the Next Big Thing

thedrum.com

The web design trends brands need to prepare for in 2019

creativebloq.com

5 ways to speed up your websites and apps

stackify.com

Top 10 Node.js Developer Tools

webdesignerdepot.com

CSS Border-Radius Can Do That?

Liam Tung

Google Chrome Labs: Use our open-source Squoosh image tool for faster page loads | ZDNet

idownloadblog.com

How to transfer playlists between popular music services with TuneMyMusic

developers.google.com

Making Fullscreen Experiences

ultimategdprquiz.com

The Ultimate GDPR Quiz

tecmint.com

How to Auto Execute Commands/Scripts During Reboot or Startup

flipboard.com

5 of the best JavaScript frameworks

Web 2.0 on Flipboard

wikihow.com

How to Be Nonchalant

Shannon Liao

‘World’s first robot lawyer’ now available in all 50 states

martechtoday.com

Natural language processing 101

machinelearningmastery.com

What Is Natural Language Processing? - Machine Learning Mastery

imore.com

How to add spaces to your Mac's Dock using Terminal

johnpapa.net

Node and npm without sudo

Node.js Foundation

Modernizing Node.js with idiomatic JavaScript – Node.js Collection – Medium

sergeyzhuk.me

Asynchronous PHP: Why?

qz.com

200 universities just launched 600 free online courses.

thoughtco.com

Free Online HTML Classes - Find the Best Free Online HTML Classes for Programmers

Travis Bradberry

Science Says These Five Things Prove You're Smart

dmarge.com

Study Reveals That Material Goods Don't Bring Happiness

Noman Ur Rehman

Working with JSON in MySQL

Ian Johnson

The Hitchhiker’s Guide to d3.js

smashingmagazine.com

Better Form Design: One Thing Per Page!

Sailing With Sails.js: An MVC-style Framework For Node.js – Smashing Magazine

What Everyone Should Know About The Process Behind App Design...

bestdesign2themes.com

Why Laravel Development Is Popular Php Frameworks

reindex.io

You Might Not Need Underscore

Laurence Bradford

8 Tech Tools To Communicate Your Ideas More Effectively

readwrite.com

5 predictions for artificial intelligence for for the coming year

Jose Aguinaga

How it feels to learn JavaScript in 2016

css-tricks.com

Adding and Leveraging a CDN on Your Website

lifehack.org

5 Secret Hacks for More Powerful Web Designs

androidauthority.com

Google Wallet's new web app is here!

Serdar Yegulalp

5 wicked-fast Python frameworks you have to try

hbr.org

Machine Learning Is No Longer Just for Experts

humaan.com

Custom HTML Markers with Google Maps - Websites, Mobile and eCommerce – Humaan

major.io

Automated Let's Encrypt DNS challenges with Rackspace Cloud DNS!

sitepoint.com

13 jQuery SelectBox/Drop-down Plugins

R.L. Adams

Five Core Skills To Learn Online Today

brainhub.eu

15 Best Node.js Tools for Developers

Philleep Florence

Get the next record in a SQL table!

Getting More with LESS! - Mixins!

Code Snippets - Get DOM Element Content

A New Year, A New Site

PhilleepEdit Webmaster

Philleep Florence Bug Tracker and Project Management has moved!

Code Snippets - HandleBars.js Helpers - ONE

2019-02-18 : 01:35

In this distro-agnostic article we will discuss the traditional methods to auto execute commands or scripts at reboot, logon, and logout in Linux

I am always fascinated by the things going on behind the scenes when I boot a Linux system and log on. By pressing the power button on a bare metal or starting a virtual machine, you put in motion a series of events that lead to a fully-functional system – sometimes in less than a minute. The same is true when you log off and / or shutdown the system.

What makes this more interesting and fun is the fact that you can have the operating system execute certain actions when it boots and when you logon or logout.

In this distro-agnostic article we will discuss the traditional methods for accomplishing these goals in Linux.

Note: We will assume the use of Bash as main shell for logon and logout events. If you happen to use a different one, some of these methods may or may not work. If in doubt, refer to the documentation of your shell.

Executing Linux Scripts During Reboot or Startup

There are two traditional methods to execute a command or run scripts during startup:

Method #1 – Use a cron Job

Besides the usual format (minute / hour / day of month / month / day of week) that is widely used to indicate a schedule, cron scheduler also allows the use of @reboot. This directive, followed by the absolute path to the script, will cause it to run when the machine boots.

However, there are two caveats to this approach:

  1. a) the cron daemon must be running (which is the case under normal circumstances), and
  2. b) the script or the crontab file must include the environment variables (if any) that will be needed (refer to this StackOverflow thread for more details).

Method #2 – Use /etc/rc.d/rc.local

This method is valid even for systemd-based distributions. In order for this method to work, you must grant execute permissions to /etc/rc.d/rc.local as follows:

# chmod +x /etc/rc.d/rc.local

and add your script at the bottom of the file.

The following image shows how to run two sample scripts (/home/gacanepa/script1.sh and /home/gacanepa/script2.sh) using a cron job and rc.local, respectively, and their respective results.

script1.sh:

#!/bin/bash
DATE=$(date +'%F %H:%M:%S')
DIR=/home/gacanepa
echo "Current date and time: $DATE" > $DIR/file1.txt

script2.sh:

#!/bin/bash
SITE="Tecmint.com"
DIR=/home/gacanepa
echo "$SITE rocks... add us to your bookmarks." > $DIR/file2.txt

Run Linux Scripts at Startup

Keep in mind that both scripts must be granted execute permissions previously:

$ chmod +x /home/gacanepa/script1.sh
$ chmod +x /home/gacanepa/script2.sh

Executing Linux Scripts at Logon and Logout

To execute a script at logon or logout, use ~.bash_profile and ~.bash_logout, respectively. Most likely, you will need to create the latter file manually. Just drop a line invoking your script at the bottom of each file in the same fashion as before and you are ready to go.

Summary

In this article we have explained how to run script at reboot, logon, and logout. If you can think of other methods we could have included here, feel free to use the comment form below to point them out. We look forward to hearing from you!


tecmint.com
Philleep Florence LLC

This unknown unknown does not support some features required to view Philleep Florence LLC. Please download a newer unknown Browser.

 
 
Philleep Florence LLC
 
Philleep Florence LLC
Image Preview