Bash script to detect when my USB is plugged in and to then sync it with a Directory

前端 未结 3 1500
陌清茗
陌清茗 2020-12-08 05:12

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?

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 06:11

    I didn't do it myself, but you can try udev rules like this:

    # Hitachi SimpleDrive mini, model HTS545050B9A300 (500 GB USB HDD)
    SUBSYSTEM=="block", ATTR{size}=="976768002", ATTRS{product}=="SimpleDrive mini", ATTRS{serial}=="2512009121920487", ACTION=="add", RUN+="/lib/udev/local.usb.hdd.sh add $devpath"
    

    Place it in /etc/udev/rules.d/90-local.rules or similar place, certainly dependable on your OS.

提交回复
热议问题