Skip to contentSkip to conversation

Check for connections and disable bluetooth in shell

DISCUSSION Jonathan Haug 2 participants 3 messages Aug 31, 2010 – Oct 7, 2010 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Dear bluetooth-experts,

I want to disable bluetooth on my system (via commandline), if there is no active bluetooth connection -- without being root.

Therefor I need a way to

1. check if there is an active bluetooth connection

2. disable bluetooth without being root

For the second part I found

dbus-send --system --type=method_call --dest=org.bluez $(dbus-send --system --print-reply --dest=org.bluez / org.bluez.Manager.ListAdapters | awk -F'"' '/at/ {print $2}') org.bluez.Adapter.SetProperty string:Powered variant:boolean:false

but this doesn't really disable bluetooth: I'm still able to deactivate bluetooth in the panel.

For the first part I could not find a solution so far.

I'm running Ubuntu 10.04.

Thanks for your help!

Jonathan Haug

#1 lore raw

Hi Jonathan,

Quoted 9 lines · Jonathan Haug

Dear bluetooth-experts,

I want to disable bluetooth on my system (via commandline), if there is no active bluetooth connection -- without being root.

Therefor I need a way to

1. check if there is an active bluetooth connection

'hcitool conn' can show that to you.

Signature · 2 lines
Gustavo F. Padovan
ProFUSION embedded systems - http://profusion.mobi
#2 lore raw

Am Dienstag, den 31.08.2010, 03:04 -0300 schrieb Gustavo F. Padovan:

Quoted 10 lines
Quoted 7 lines

I want to disable bluetooth on my system (via commandline), if there is no active bluetooth connection -- without being root.

Therefor I need a way to

1. check if there is an active bluetooth connection

'hcitool conn' can show that to you.

Just to complete this thread:

Thanks Gustavo! I'm now using the following script:

if grep -q off-line /proc/acpi/ac_adapter/ACAD/state; then
if !(hcitool con | grep -q "state"); then
rfkill block bluetooth
fi
fi

May it be helpful for someone.

Greetings

Jonathan