我有一个运行 Debian 的 BeagleBone Black,并通过 USB 连接了一个 868Mhz 加密狗,该加密狗显示在 /dev/ttyACM0 在某些情况下,重新启动后该设备不会显示。因此我编写了以下 bash 脚本并将其添加到 crontab (@reboot)
#!/bin/bash
# Checks if CUL is available. Reboots otherwise
sleep 5m
if [ "ls /dev | grep ttyACM0" ];
then
echo "CUL is available"
else
echo "CUL is not available. Rebooting..."
reboot
fi
Run Code Online (Sandbox Code Playgroud)
但这个办法似乎行不通。
你的 if 条件应该是:
[ -c /dev/ttyACM0 ]
Run Code Online (Sandbox Code Playgroud)
也许您还应该对主要和次要号码添加更多检查。
这是指南的链接bash if。