This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# follow https://unix.stackexchange.com/a/634849 | |
# Usage | |
# getdevicename 1234:abcd | |
# getdevicenum 1234:abcd | |
# where | |
# 1234 is the IdVendor | |
# abcd is the IdProduct | |
# Those values could be captured using lsusb | |
getdevicename() { | |
idV=${1%:*} | |
idP=${1#*:} | |
for path in `find /sys/ -name idVendor 2>/dev/null | rev | cut -d/ -f 2- | rev`; do | |
if grep -q $idV $path/idVendor; then | |
if grep -q $idP $path/idProduct; then | |
find $path -name 'device' | grep block | rev | cut -d / -f 2 | rev | |
fi | |
fi | |
done | |
} | |
getdevicenum() { | |
idV=${1%:*} | |
idP=${1#*:} | |
for path in `find /sys/ -name idVendor 2>/dev/null | rev | cut -d/ -f 2- | rev`; do | |
if grep -q $idV $path/idVendor; then | |
if grep -q $idP $path/idProduct; then | |
find $path -name 'device' | rev | cut -d / -f 8 | rev | grep "-" | head -n1 | |
fi | |
fi | |
done | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
simple: | |
source get_device.sh | |
getdevicename 1234:abcd | |
getdevicenum 1234:abcd | |
script: | |
#Device VENDOR ID | |
: ${DEVICE_VENDOR:="1234"} | |
#Device PRODUCT ID | |
: ${DEVICE_PRODUCT:="abcd"} | |
source ./get_device.sh | |
DEVICE_PATH=`getdevicename ${DEVICE_VENDOR}:${DEVICE_PRODUCT}` | |
echo "Device Path is $DEVICE_PATH" | |
cat /sys/bus/usb/devices/`getdevicenum ${DEVICE_VENDOR}:${DEVICE_PRODUCT}`/power/autosuspend |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
I use the getdevicenum to automate disabling the auto-suspend, through the
/etc/rc.local
as instructed by this answer