Better way to script USB device mount in Linux

前端 未结 5 648
鱼传尺愫
鱼传尺愫 2020-12-15 14:26

I\'m writing a python module for a device that interacts with a user supplied USB memory stick. The user can insert a USB memory stick in the device USB slot, and the device

5条回答
  •  醉话见心
    2020-12-15 14:53

    I'm not entirely certain how portable this is. Also, this information would presumably also be available over D-Bus from udisks or HAL but neither of those is present on my system so I can't try. It seems to be reasonably accurate here regardless:

    $ for i in /sys/class/block/*; do
    >     /sbin/udevadm info -a -p $i | grep -qx '    SUBSYSTEMS=="usb"' &&
    >     echo ${i##*/}
    > done
    sde
    sdf
    sdg
    sdh
    sdi
    sdj
    sdj1
    $ cd /sys/class/block/
    $ for i in *; do [[ $(cd $i; pwd -P) = */usb*/* ]] && echo $i; done
    sde
    sdf
    sdg
    sdh
    sdi
    sdj
    sdj1
    

提交回复
热议问题