首页 > 解决方案 > 一个简单的蓝牙外壳脚本

问题描述

您好,我需要有关此蓝牙 shell 脚本的帮助,因为您可以看到蓝牙脚本正在搜索具有特定 MAC 地址的蓝牙设备并自动连接到它,但我的设备有时会关闭并再次打开!由于一个问题,当我失去蓝牙连接时,我需要脚本非常清楚!他自动搜索并再次快速连接到它。

#!/bin/bash
MAC="XX:XX:XX:XX:XX:XX"
powered() {
    echo "show" | bluetoothctl | grep "Powered" | cut -d " " -f 2
}

connected() {
    echo "info ${MAC}" | bluetoothctl | grep "Connected" | cut -d " " -f 2
}

while true
do
    sleep 1
    if [ $(powered) = yes ] && [ $(connected) = no ]; then
        echo "connect ${MAC}" | bluetoothctl
        sleep 5
    fi
done

标签: bashshellunixbluetoothsh

解决方案


推荐阅读