I'm currently programming two scripts, one to connect to a wifi network, the other one to disconnect.
The connect script works well, however when I'm do
sudo ifconfig wlan0 down
sudo ifconfig wlan0 up
The interface automatically reconnect to the network even if there is nothing about wlan0 in /etc/network/interfaces.
However if I reboot, wlan0 is not connected.
Here is my script for those you are interested in
#!/bin/bash
SSID="ssid"
PASSWORD="pass"
CONF_FILE="/etc/wpa_supplicant/$SSID.conf"
if [ -f "$CONF_FILE" ]; then
echo "wpa configuration file already exists"
else
echo "wpa configuration file doesn't exists"
#Generating configuration file
sudo wpa_passphrase $SSID $PASSWORD > $CONF_FILE
#Delete the line containing the password
sudo sed -i '/$PASSWORD/d' $CONF_FILE
fi
#Connecting to network
sudo wpa_supplicant -c $CONF_FILE -i wlan0 &
I think it's because wpa_supplicant is still running in background, does anybody knows how to kill the wpa_supplicant running process without knowing its pid?
Edit : I confirm it comes from the wpa-supplicant running in background. The only way I found to solve it is to call a
sudo killall wpa_supplicant
However this solution doesn't satisfy me, imagine I have another instance of wpa_supplicant running on another interface I will loose all my network connections. Pretty sure there is a better way to kill the process associated to this specific interface. I'll dig around. Hope someone already had this situation.