Skip to content

Instantly share code, notes, and snippets.

@andmax
Created June 7, 2023 11:57
Show Gist options
  • Save andmax/d6c02d49415b99d981a6a74d796edc8c to your computer and use it in GitHub Desktop.
Save andmax/d6c02d49415b99d981a6a74d796edc8c to your computer and use it in GitHub Desktop.
Script to restart bluetooth
#!/usr/bin/bash
echo 'clearing dmesg...';
sudo dmesg -c && clear;
DEVICE=$(rfkill list all | grep -o 'hci*.');
sudo hciconfig ${DEVICE} down;
sudo rmmod btusb;
sudo service bluetooth disable;
sudo modprobe btusb;
sudo hciconfig ${DEVICE} up;
sudo service bluetooth enable;
echo '\n~~rfkill:';
rfkill unblock bluetooth;
rfkill list all;
echo "\n~~~DMESG:";
sudo dmesg | grep -i bluetooth;
echo '\n~~~bluetooth status:';
sudo service bluetooth status;
echo '\n~~~if failed try manually:';
bluetoothctl power on;
bluetoothctl devices;
read DEVICE_TO_CONNECT;
bluetoothctl connect ${DEVICE_TO_CONNECT}
echo "~~~\nFINISH UP:\n~~~~run bluetoothctl;\n~~~~~power on && devices && connect";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment