3

I have a small server, with Ubuntu OS, running 24/7, and with a script that is triggered only once a day to retrieve data from the net, and copy it to an external USB hard drive. This data copy is managed through a bash script. Roughly, the data copy starts at 00:00 and finishes at 5:00.

Because the external USB HDD is idle for a long period of time, I would like to start it only few minutes before data copy, and switch it off few minutes after data copy, directly through my bash script.

I had a look, and mostly identified 2 solutions, which I am not able to differentiate.

1. Using bind/unbind.

echo '1-2.2:1.0' > /sys/bus/usb/drivers/r8712u/bind   # switch on
echo '1-2.2:1.0' > /sys/bus/usb/drivers/r8712u/unbind # switch off

2. Using autosuspend, from this SO question.

echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms"
echo "auto" > "/sys/bus/usb/devices/usbX/power/control"

Please, what is the difference, and which one would be the most appropriate for my use case?

Thanks a lot for your help. Have a good day, bests

1
  • I'm trying to power on/off usb drive using this command, what I can't figure out is how do you find out what's the bus-port number you put on the echo command. Commented Mar 4, 2022 at 12:48

1 Answer 1

3

Your second option "autosuspend" lets the operating system's power management decide whether to drive down the device, with some rules about particular timeout or some automatism.  It would still keep your disk available for other programs.

In your first option, the "unbind" is similar to pulling the USB cable.  This will cause trouble if another script beside yours is using the disk.  IMHO, an "unbind/bind" combo would be more appropriate as a hard reset when some USB device does not react anymore for whatever reason, e.g., because it shut off on its own decision.

So option number 2 sounds more appropriate for your use case.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.