Last active
July 24, 2019 17:39
-
-
Save hfreire/32deb6be3791f15692feaa8954e954fe to your computer and use it in GitHub Desktop.
Enable/disable power on Raspberry Pi USB ports + Ethernet
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
#!/bin/sh | |
SOC_USB=/sys/devices/platform/soc/20980000.usb | |
if [ ! -d $SOC_USB ]; | |
then | |
SOC_USB=/sys/devices/platform/soc/3f980000.usb # Raspberry Pi 3 | |
fi | |
BUSPOWER=$SOC_USB/buspower | |
is_usb_power_on () | |
{ | |
cat $BUSPOWER | grep "Bus Power = 0x1" >/dev/null | |
} | |
case $1 in | |
stop) | |
if is_usb_power_on | |
then | |
echo 0x0 > $BUSPOWER | |
fi | |
;; | |
start) | |
if ! is_usb_power_on | |
then | |
echo 0x1 > $BUSPOWER | |
fi | |
;; | |
status) | |
if is_usb_power_on | |
then | |
echo "USB power is on" | |
else | |
echo "USB power is off" | |
fi | |
;; | |
*) | |
echo "Usage: $0 start|stop|status" >&2 | |
exit 2 | |
;; | |
esac | |
exit 0 |
@dotps1 if you run commands with redirection a simple sudo doesn't work, because the redirection is done by the unprivileged shell (before sudo starts).
Instead you can replace
echo XYZ >PROTECTED-FILE
by something like
echo XYZ | sudo tee PROTECTED-FILE
(and appending like >>FILE would be replaced by
| sudo tee -a FILE`)
or become root by sudo su
first...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the code for the rpi 3b doesn't work, permission denied, even using elevation.