Zxuan
Posts: 3
Joined: Sat Mar 24, 2018 2:39 pm

How To Auto Run A Script on Boot

Sat Mar 24, 2018 3:09 pm

So I've just bought a raspberry pi 3 model b a few months ago, I flashed the latest raspbian image at the time(November/December 2017) and modified it with a wireless mouse, HDMI TV along with help of copy paste of commands from a file on a pendrive to install an on screen keyboard, then I modified VNC to connect to my laptop through a Ethernet cable, it worked pretty well. But I then tried another VNC service to connect my Pi to my Android Phone through USB, it worked but it ruined my VNC connection to my laptop so I managed to connect it to another HDMI TV to see what's not working. It turns out that my wifi and ethernet(dhcp) are not working due to some files(my guess). I tried solving the problem from the software but I just couldn't , so I flashed the raspbian file(same file and version) again after formatting the sd card. I need to make it auto login and run

Code: Select all

apt-get update
and setup vnc to connect it to the laptop again. I do not have access to a hdmi monitor currently and wish to solve the problem by editing files from my linux system on my computer.

Thanks,
Zxuan.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: How To Auto Run A Script on Boot

Sat Mar 24, 2018 3:51 pm

sounds little bit confusing, i would say that has nothing to do with needing a script at boot.
do not format, do not burn old images...

what we talk about is a headless setup: ( of RPI3B from a windows PC?)
-a- on PC download newest image https://www.raspberrypi.org/downloads/raspbian/ best via torrent
-b- on PC burn that to a min 8GB SD card with https://etcher.io/
-c- on the card make a (empty) file named
ssh
what will allow to login remotely putty / ssh
-d- make a file named
wpa_supplicant.conf

Code: Select all

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
	ssid="your ssid"
	psk="your password"
	key_mgmt=WPA-PSK
} 
what will autologin to WIFI network ( even without using a ethernet cable RPI <-> router )
-e put that sd card in a RPI3 just with a power cable connected
try to find the RPI_IP of that booted RPI ( in router or by network scanner tools like mobile FING)

-f on PC
use putty / ssh to login RPI
pi@RPI_IP
raspberry

use in terminal
sudo raspi-config
enable VNC
reboot

-g- on PC install start realVNC viewer and login
RPI_IP
pi
raspberry
Last edited by KLL on Sun Mar 25, 2018 12:17 am, edited 1 time in total.

gkaiseril
Posts: 679
Joined: Mon Aug 08, 2016 9:27 pm
Location: Chicago, IL

Re: How To Auto Run A Script on Boot

Sat Mar 24, 2018 4:25 pm

Have you looked at the raspberry configuration program on the desk top (Preferences => Raspberry Pi Configuration) or the command line raspi-config for setting the auto login for the pi user and starting the SSH and the VNC serices. As for the auto run of a bash (shell) script there are a number of possible ways to do this. See Remote Access for more information on how to use VNC and SSH from remote computers.

You can start command in the rc.local file to start a bash script or other executable program. You need to set permissions and file path. Also you may need to use sudo to run some commands as root.Or one can use the Cron tool to schedule tasks.

Five ways to Run a Program on Yhour Raspberry Pi at Stgartup

There are also ways to start commands when only the desktop or desktop are started.
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.

Zxuan
Posts: 3
Joined: Sat Mar 24, 2018 2:39 pm

Re: How To Auto Run A Script on Boot

Sun Mar 25, 2018 3:21 pm

KLL wrote:
Sat Mar 24, 2018 3:51 pm
sounds little bit confusing, i would say that has nothing to do with needing a script at boot.
do not format, do not burn old images...

what we talk about is a headless setup: ( of RPI3B from a windows PC?)
-a- on PC download newest image https://www.raspberrypi.org/downloads/raspbian/ best via torrent
-b- on PC burn that to a min 8GB SD card with https://etcher.io/
-c- on the card make a (empty) file named
ssh
what will allow to login remotely putty / ssh
-d- make a file named
wpa_supplicant.conf

Code: Select all

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
	ssid="your ssid"
	psk="your password"
	key_mgmt=WPA-PSK
} 
what will autologin to WIFI network ( even without using a ethernet cable RPI <-> router )
-e put that sd card in a RPI3 just with a power cable connected
try to find the RPI_IP of that booted RPI ( in router or by network scanner tools like mobile FING)

-f on PC
use putty / ssh to login RPI
pi@RPI_IP
raspberry

use in terminal
sudo raspi-config
enable VNC
reboot

-g- on PC install start realVNC viewer and login
RPI_IP
pi
raspberry
Thanks for your solution KLL, I'm very grateful for the in depth explaination and will try the solutiton as soon as possible(probably tomorrow)
Will let u know if i encounter any problems. Btw, will I need to change the country to mine cos I don't live in US?
Again, thanks for taking your time to help me.
Zxuan

Zxuan
Posts: 3
Joined: Sat Mar 24, 2018 2:39 pm

Re: How To Auto Run A Script on Boot

Sun Mar 25, 2018 3:24 pm

gkaiseril wrote:
Sat Mar 24, 2018 4:25 pm
Have you looked at the raspberry configuration program on the desk top (Preferences => Raspberry Pi Configuration) or the command line raspi-config for setting the auto login for the pi user and starting the SSH and the VNC serices. As for the auto run of a bash (shell) script there are a number of possible ways to do this. See Remote Access for more information on how to use VNC and SSH from remote computers.

You can start command in the rc.local file to start a bash script or other executable program. You need to set permissions and file path. Also you may need to use sudo to run some commands as root.Or one can use the Cron tool to schedule tasks.

Five ways to Run a Program on Yhour Raspberry Pi at Stgartup

There are also ways to start commands when only the desktop or desktop are started.
Thanks gkaiseril for your suggestion, I will try it as soon as possible and will let you know if it works.
Thanks,
Zxuan

Return to “Beginners”