bash - 一个简单的蓝牙外壳脚本
问题描述
您好,我需要有关此蓝牙 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
解决方案
推荐阅读
- python - 如何从广告创意 Facebook 营销 API 获取广告 ID
- javascript - 获取客户端javascript代码中可用的node.js服务器端对象
- r - 使用特定列的值从其他行中减去,但列索引在 R 中的文件之间移动
- spring - 使用反应式 DB 客户端扩展 Spring WebFlux 应用程序时出现问题:Maven 依赖项冲突?
- git - 如何 grep Git 提交消息或关键字的差异并输出更改(聚合)的文件名?
- javascript - CakePHP scriptBlock 没有在 HTML 页面中添加任何 JavaScript
- node.js - 为什么我不能直接使用 req.body 作为参数?
- javascript - React Native,为什么 react-native run-android 不起作用?
- hadoop - 使用 cygwin 在窗口 10 上配置 Hive:路径错误
- python - 在 pylint 和 mypy 中处理 Python 类重新定义警告