Skip to content

Instantly share code, notes, and snippets.

@wch
Created January 7, 2014 19:22
Show Gist options
  • Save wch/8305204 to your computer and use it in GitHub Desktop.
Save wch/8305204 to your computer and use it in GitHub Desktop.
Script for restarting wpa_supplicant in debug mode
#!/bin/sh
# set wpa_supplicant debug level to 1, disable timestamps, disable show_keys
[ "$UID" == 0 ] || { echo "Only root can run this"; exit 0;}
LOG="/var/log/wpa_supplicant.log"
echo "Stopping NetworkManager"
service network-manager stop
sleep 1
echo "Killing current wpa_supplicant"
pkill -9 wpa_supplicant$
sleep 1
echo "Starting wpa_supplicant in DBUS & DEBUG mode, log is in $LOG"
wpa_supplicant -dd -u -f $LOG -B
sleep 1
echo "Starting NetworkManager"
service network-manager start
@wch
Copy link
Author

wch commented Jan 7, 2014

To run this:

sudo ./wpa_debug.sh

This is originally from http://oflabs.wordpress.com/2011/10/30/debug-wpa_supplicant-in-dbus-mode/ and modified to work on Ubuntu 13.10.

@royaldark
Copy link

FYI, the hashbang at the beginning should use /bin/bash. With /bin/sh, I get /home/joe/bin/wpa_debug.sh: 5: [: unexpected operator

@mdupuy
Copy link

mdupuy commented Apr 9, 2018

I think most people will now use systemctl to stop and start services and wpa_cli to enumerate any reconfigurations. Also, in many cases, I find reloading dhcpcd useful for forcing the wifi device to start a session. For anyone else arriving here in 2018 via Google...

#!/bin/bash

# set wpa_supplicant debug level to 1, disable timestamps, disable show_keys

[ "$UID" == 0 ] || { echo "Only root can run this"; exit 0;}

LOG="/var/log/wpa_supplicant.log"

echo "Stopping NetworkManager"
#service network-manager stop
systemctl stop networking.service
sleep 1 

echo "Killing current wpa_supplicant"
pkill -9  wpa_supplicant$
sleep 1 

wpa_cli reconfigure 

echo "Starting wpa_supplicant in DBUS & DEBUG mode, log is in $LOG"
wpa_supplicant -dd -u -f $LOG -B
sleep 1

#systemctl restart wpa_supplicant;
systemctl daemon-reload
systemctl restart dhcpcd

echo "Starting NetworkManager"
#service network-manager start
systemctl start networking.service

@eric-bentley
Copy link

eric-bentley commented Oct 3, 2018

could just use python to change on the fly (thanks to co-worker for code)

#!/usr/bin/python
import dbus

DBUS_PROP_IFACE = 'org.freedesktop.DBus.Properties'
WPA_OBJ = '/fi/w1/wpa_supplicant1'
WPA_IFACE = 'fi.w1.wpa_supplicant1'

bus = dbus.SystemBus()
proxy = bus.get_object(WPA_IFACE, WPA_OBJ)
wpas = dbus.Interface(proxy, DBUS_PROP_IFACE)
debug_level = wpas.Get(WPA_IFACE, "DebugLevel")
print(debug_level)
debug_level = wpas.Set(WPA_IFACE, "DebugLevel", "info")
debug_level = wpas.Get(WPA_IFACE, "DebugLevel")
print(debug_level)

@mapcuk
Copy link

mapcuk commented Mar 18, 2019

What if just run sudo wpa_cli log_level debug ?

@ranganathanm
Copy link

May be too late. In the latest wpa_supplicant, you have to enable logging by building it with DEBUG_LOG_FILE=y in the .config file to enable the -f flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment