0

I bought my first Raspberry yesterday (RPi 3).

I have already installed an ssh server and I would like to run a script that create an hotspot on boot.

My intent is to boot the RPi 3, connect to the hotspot with my Android and manage it via SSH.

I already tried:

  1. Putting the path of my script in /etc/rc.local
  2. Create a service in /etc/init.d
  3. crontab -e -> @reboot

but the script is launched before network interfaces or it doesn't work at all.

I'll post my script here:

#!/bin/bash

# install
# apt-get install airmon-ng hostapd isc-dhcp-server -y

killall dhcpd
killall hostapd
airmon-ng check kill

. conf.cfg

echo "Configuring hostapd..."

###########################################################

rm -r /etc/hostapd/*

(echo "interface=$interfaccia
driver=nl80211
ssid=$ssid
hw_mode=g
channel=$canale
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=$hidessid
wpa=$wpa
wpa_passphrase=$wpa_passphrase
wpa_pairwise=TKIP
rsn_pairwise=CCMP") >> /etc/hostapd/hostapd.conf

#hostapd /etc/hostapd/hostapd.conf >/dev/null &

hostapd /etc/hostapd/hostapd.conf >/dev/null &

echo "Hostapd started."

echo "Wait to start server dhcp..."
sleep $sleep_time

###########################################################

#mkdir /var/lib/dhcp
#touch /var/lib/dhcp/dhcpd.leases

ifconfig $interfaccia  up
ifconfig $interfaccia  192.168.0.1 netmask 255.255.255.0

touch /var/run/dhcpd.pid
chmod 777 /var/run/dhcpd.pid

rm /etc/dhcpd.conf

(echo "authoritative;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.0.0 netmask 255.255.255.0 {
        option subnet-mask 255.255.255.0;
        option broadcast-address 192.168.0.255;
        option routers 192.168.0.1;
        option domain-name-servers 192.168.0.1; #DNS SERVER
        range 192.168.0.2 192.168.0.202;
}") >> /etc/dhcpd.conf

#dhcpd -q -cf /etc/dhcpd.conf $interfaccia  >/dev/null &

dhcpd -q -cf /etc/dhcpd.conf $interfaccia  >/dev/null &

echo "HOTSPOT ONLINE, SSID: $ssid"

and conf.cfg here:

#General
interfaccia=wlan0
internet=wlan1
sleep_time=1

#Network
ssid="TESTNET"
bssid=00:AA:11:BB:22:CC
canale=6
hidessid=0          #Hide SSID
wpa=0               #3=ON 0=OFF
wpa_passphrase="testtest"   #Min 8 char

This script works fine if launched from terminal after login in XServer.
But I want make it work before login without XServer and before the login. (Log-in should be via ssh, because no display will be connected to the RPi 3)

1

My mistake was to try the whole process in a virtual machine, today i tried directly on the raspberry and i solved it putting this line of code in the /etc/rc.local file:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/script_path/./script.sh

exit 0

I hope this can help somebody else with the same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.