Info über Wechseldatenträger

Aus Si:Wiki von Siegrist SystemLösungen - Informatik und Rezepte
Wechseln zu: Navigation, Suche
Get some info about removable devices like Device, Vendor, Model, Serial etc.
Useful for creating UDEV-Rules.
#!/bin/bash
 
REMOVABLE_DRIVES=""
i=0
for _device in /sys/block/*/device; do
    if echo $(readlink -f $_device)|egrep -q "usb"; then
        _disk=`echo $_device | cut -f4 -d/`
        _path=`echo $_device | cut -f5 -d/ --complement`
        _id_devname=`udevadm info --export --query=all --path=$_path | grep DEVNAME= | cut -f2 -d=`
        _id_model=`udevadm info --export --query=all --path=$_path | grep ID_MODEL= | cut -f2 -d=`
        _id_fs_type=`udevadm info --export --query=all --path=$_path | grep ID_FS_TYPE= | cut -f2 -d=`
        _id_vendor=`udevadm info --export --query=all --path=$_path | grep ID_VENDOR= | cut -f2 -d=`
        _id_serial=`udevadm info --export --query=all --path=$_path | grep ID_SERIAL= | cut -f2 -d=`
 
        echo -e "\nDevice : $_id_devname\nModel  : $_id_model\nVendor : $_id_vendor\nFS-Type: $_id_fs_type\nSerial : $_id_serial\nPath   : $_path"
 
        REMOVABLE_DRIVES="$REMOVABLE_DRIVES $_disk"
        ((i++))
    fi
done
echo -e "\n$i Removable drive(s) found: $REMOVABLE_DRIVES\n"