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:
- 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