如何控制循环并从 USB 端口读取实时信息,并在插入或移除 USB 时保存每个输出。我知道下面的代码可以改进,请提供帮助。
#!/bin/bash
time=$(date)
HOST=$(hostname)
if [ -n "$(lsusb | grep SiGma)" ];
then
echo "Signal connected at { $time } Hosted by: $HOST"
echo "__________________________________________________"
else
echo "Signal disconnected at { $time } Hosted by: $HOST"
echo "__________________________________________________"
fi
答案1
让你的脚本看起来像这样:
#!/bin/bash
time=$(date)
HOST=$(hostname)
if [ -n "$(lsusb | grep SiGma)" ];
then
echo "SiGma connected at { $time } Hosted by: $HOST" >> ~/sigma.log
else
echo "SiGma disconnected at { $time } Hosted by: $HOST" >> ~/sigma.log
fi
关注后这个帖子或者这个帖子在插入或拔出 USB 设备后自动运行脚本。~/sigma.log
当插入或拔出简短明文描述中包含“SiGma”字符串的 USB 设备时,您将在文件中看到结果。