bash脚本检测时,我的USB插上电源并然后用目录同步,它 [英] Bash script to detect when my USB is plugged in and to then sync it with a Directory
问题描述
是否有一个Bash脚本和/或守护,我可以写,将检测特定的USB驱动器,然后同步与目录驱动器?
有关备查,这里是如何在检测到USB驱动器的运行bash脚本。
连接设备和运行的lsusb
来检索设备的信息。你应该看到类似这样的:
$的lsusb
公交002设备039:ID 0bc2:2100希捷RSS LLC
块引用>在这种情况下,该装置的销售商ID是0bc2和产品ID是2100
现在你可以使用你选择的文本编辑器创建你的udev规则。
$ sudo的VI /etc/udev/rules.d/85-my_usb_device_rule.rules
块引用>和补充一点:
ACTION ==增加,SUBSYSTEM ==USB,SYSFS {idVendor} ==0bc2
SYSFS {} idProduct ==2100,RUN + =/家/ MYHOME / my_script
块引用>
/家庭/ MYHOME / my_script
是路径到脚本,它会不管你想要做的。要确保检测脚本将执行向右走,运行这个命令来重新加载udev规则:
$ sudo的udevadm控制--reload规则
块引用>这是在Fedora 14测试。
Is there a Bash script and/or daemon that I can write that will detect a specific USB drive and then sync that drive with a directory?
解决方案For future reference, here's how to run a bash script upon detection of a USB drive.
Connect your device and run
lsusb
to retrieve the device's info. You should see something similar to this:$ lsusb Bus 002 Device 039: ID 0bc2:2100 Seagate RSS LLC
In this case, the vendor ID of the device is 0bc2 and the product ID is 2100.
Now you can create your UDEV rule using a text editor of your choice.
$sudo vi /etc/udev/rules.d/85-my_usb_device_rule.rules
And add this:
ACTION=="add", SUBSYSTEM=="usb", SYSFS{idVendor}=="0bc2", SYSFS{idProduct}=="2100", RUN+="/home/myhome/my_script"
/home/myhome/my_script
is the path to your script which it would do whatever you want.To make sure the detection script will execute right away, run this command to reload the UDEV rules:
$sudo udevadm control --reload-rules
This was tested on Fedora 14.
这篇关于bash脚本检测时,我的USB插上电源并然后用目录同步,它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!