Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a USB controlled power strip that has a single usb port.

enter image description here

If my computer is turned on and connected via usb to the power strip, the power strip will provide electricity to all the sockets. I want to programatically disable power to the usb port on the computer which is connected to the power strip.

This does not work:

$ echo suspend > /sys/bus/usb/devices/usb*/power/level
-bash: echo: write error: Invalid argument

Is there some other way to do this? I would like to be able to connect to my server from somewhere else and turn off power to all the devices connected to the power sockets.

share|improve this question

5 Answers 5

up vote 5 down vote accepted

Does the power strip do anything beyond read the +5V a connected USB port provides? (Do you see anything in dmesg when you attach it? Does the output of lsusb change after you plug it in?) If not, the kernel may not even recognize that anything is attached. You can't tell a device to suspend if it never enumerates itself: it would never show up under /sys/bus/usb/devices, and with USB you suspend devices, not ports.

Additionally, from Documentation/usb/power-management.txt:


            This file contains one of two words: "on" or "auto".
            You can write those words to the file to change the
            device's setting.

            "on" means that the device should be resumed and
            autosuspend is not allowed.  (Of course, system
            suspends are still allowed.)

            "auto" is the normal state in which the kernel is
            allowed to autosuspend and autoresume the device.

            (In kernels up to 2.6.32, you could also specify
            "suspend", meaning that the device should remain
            suspended and autoresume was not allowed.  This
            setting is no longer supported.)

So according to that last little statement, if you have a kernel newer than 2.6.32 it sounds like you cannot force a USB device to suspend anyway.

Sorry that I can't give you the answer you actually wanted, what you were trying to do sounds pretty neat, but I hope it was helpful.

share|improve this answer
Thanks for the answer. The power strip seems to work only by detecting the +5V - it does not seem to have any logic inside. Also, the lsusb does not show the power strip. I was fearing that something like this might be the case. I thought it may be possible to control other electrical devices by shutting down the voltage for the power strip USB. Perhaps there is a controllable usb-switch that can be bought somewhere, hm... –  axel22 May 16 '11 at 20:33
# To enforce suspend immediately when device is unused:
echo -n "0" >$DEV_POWER_PATH"/power/autosuspend_delay_ms"
echo -n "auto" >$DEV_POWER_PATH"/power/control"
# Make the device was not used
rmmod drv_name # see result of lsmod

# Power on: 
echo -n "2000" >$DEV_POWER_PATH"/power/autosuspend_delay_ms"
echo -n "on" >$DEV_POWER_PATH"/power/control"
# Make the device was used.
modprobe drv_name
share|improve this answer

how about this:

for i in /sys/bus/usb/devices/usb* ; do echo "suspend" > $i/power/level; done

For debugging purposes, you can add an "echo $i" in there somewhere to let you know which devices are being hit.

share|improve this answer
Thanks for the answer! Unfortunately, this just outputs the "Invalid argument" error message for all five usb devices. –  axel22 May 16 '11 at 19:57
Hmm. That makes it seem like the usb ports don't accept that command. Which kernel are you running? (uname -r) –  Hack Saw May 16 '11 at 20:10
I am running 2.6.38-8-generic-pae. I've read somewhere that the "suspend" feature was disabled for this kernel. –  axel22 May 16 '11 at 20:29
I wonder if the ports would turn off if you unloaded the device driver. Kind of drastic, but... –  Hack Saw May 16 '11 at 20:32
Is it possible to load/unload the device driver for the usb dynamically, without rebooting? Is there a way to do it on a per-port basis? –  axel22 May 16 '11 at 20:34

I did have the same issue on my side. a ls -al showed that only root have write access

-rw-r--r-- 1 root root 4.0K May  8 10:27 level

So I tried to do the same command with sudo but I still had the same error

The only way I found to make it works was to do a chmod on this file then to write into it. Also. On my side control and autosuspend_delay_ms was not sufficient. I had to unbind it to be able to really suspend it.

sudo chmod 777 /sys/bus/usb/devices/2-1.7/power/control
sudo chmod 777 /sys/bus/usb/devices/2-1.7/power/autosuspend_delay_ms
sudo chmod 777 /sys/bus/usb/drivers/usb/unbind
echo "auto" > "/sys/bus/usb/devices/2-1.7/power/control"
echo "0" > "/sys/bus/usb/devices/2-1.7/power/autosuspend_delay_ms"
echo -n "2-1.7" > /sys/bus/usb/drivers/usb/unbind
share|improve this answer

Thanks Patrice for your solution, that one worked for me. The only problem that I had was that I couldn't figure out how to restart the device! Trying to just reverse the process with

echo "on" > "/sys/bus/usb/devices/2-1.7/power/control"
echo "2000" > "/sys/bus/usb/devices/2-1.7/power/autosuspend_delay_ms"
echo -n "2-1.7" > /sys/bus/usb/drivers/usb/bind

did not work. Finally, the only thing that I was able to get to do it was to reset the entire USB bus using the C code ioctl(fd, USBDEVFS_RESET, 0) and this seems to force it to restart. This is done by compiling the code found here (i.e. with gcc usbreset.c -o usbreset) and running it on bus #2 in this case.

usbreset /dev/bus/usb/002/001

By doing this all of the devices on bus 2 seem to come back with their default properties set.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.