forked from jnweiger/led-name-badge-ls32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usb-power.sh
executable file
·31 lines (29 loc) · 985 Bytes
/
usb-power.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
###############################################################
# It will power on/off a usb device based on a string found in dmesg output.
#
# Example for the led-badge:
#
# usb-power.sh off "Product: LS32 Custm HID"
# - This code does not work with a Lenovo-T440s running Mint. Not sure why.
###############################################################
if [[ $2 == "" ]]; then
echo "Usage: $0 [on|off] DMESG_STRING"
exit;
fi
USB_DEV=$(dmesg | grep -o "usb .*: $2" | tail -n 1 | awk '{print $2}' | sed 's/://')
if [[ $USB_DEV == "" ]]; then
echo "Device not found";
exit;
fi
echo using USB_DEV=$USB_DEV
if [[ $1 == "on" ]]; then
echo "2000" > /sys/bus/usb/devices/$USB_DEV/power/autosuspend_delay_ms
echo "on" > /sys/bus/usb/devices/$USB_DEV/power/control
elif [[ $1 == "off" ]]; then
echo "0" > /sys/bus/usb/devices/$USB_DEV/power/autosuspend_delay_ms
echo "auto" > /sys/bus/usb/devices/$USB_DEV/power/control
else
echo "Unknown action: $1"
exit;
fi