Run bash script on startup (Ubuntu-NanoPi)

you can execute a script when Nano Pi boots up.

You can add your script executable command to the bottom of .bashrc that will run your script every time open a terminal (or run a new instance of bash).

1. Make sure you are in the pi folder:

$ cd ~

2. Create a file and write a script to run in the file:

$ sudo nano run.sh

3. Save and exit: Ctrl+X, Y, Enter

4. Open up .bashrc for configuration:

$ sudo nano .bashrc

.bashrc is NOT intended to run scripts. It is run each time a non-login interactive shell is started and is used to configure the shell.
~/.bashrc: executed by bash(1) for non-login shells.

5. Scroll down to the bottom and add the line: ./run.sh

6. Save and exit: Ctrl+X, Y, Enter

— — — — — — — — — — — — — — — — — — — — —

If you are looking for a solution that works on bootup to the console, take a look at this link. Basic rundown:

  1. Create a file for your startup script and write your script in the file:
$ sudo nano /etc/init.d/run.sh

2. Save and exit: Ctrl+X, Y, Enter

3. Make the script executable:

$ sudo chmod 755 /etc/init.d/run.sh
or
$ chmod +x run.sh

4. Register script to be run at startup:

$ sudo update-rc.d run.sh defaults

--

--

--

BackEnd Dev, Django

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Myaza customer care number/9883996727

Quick and Nimble at WW

Validate, Authenticate and Secure — Oh my!

Serverless Eventing: What is it anyway?

Python: mock function with parameters (pytest + unittest)

Alvin’s Dew Drop Daily — Issue #47

How to set up a brand new Macbook

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nima dorostkar

Nima dorostkar

BackEnd Dev, Django

More from Medium

Remote backend for tfcdk

A small, yet undocumented bug with yml files (docker-compose.yml) and anchors.

Multi-Node Docker Swarm on CentOS 8 Stream, Installed on  ESXi Host

Generate self signed certificates with SAN using openSSL