0

I need to start/stop an external hard drive (USB) from a shell or python script. Actually the external hard drive automatically stops when ejected. So, is it possible to programmatically eject / start an external hard drive? Something like USBDeview does for Windows :-)

Update:

My intended use case: I want to run a nightly backup to the external drive. As the drive is quite loud and to save on energy, I only want it to be active during the backup. I likely won't use Time Machine, but my own backup script.

  • 1
    Can you explain the wider scope of the problem, and what you mean by 'start/stop'? You can mount and unmount the drive in the shell very easily with mount and umount. – benwiggy Mar 02 '20 at 09:32
  • Thanks, good question - I updated my question with the use case :-) – me.at.coding Mar 02 '20 at 12:35
  • 1
    Long story short..you can't. However, a "noisy" hard drive is a red flag for me. Whether it's a well used drive on it's last legs or a new drive with poor quality components, you shouldn't have noisy drives in this day and age. Spend the money and get a new one - after all, you're backing up your data. I always ask my clients the same thing when they try to justify sketchy hardware..."How much is your data worth?" I'll bet it's worth orders of magnitude more than a new USB drive ($70-100USD) – Allan Mar 02 '20 at 13:51
  • I'm with Allan: a noisy drive is a worrisome drive. Also, a mechanical drive's power consumption is between 5 and 7 watts. While energy saving is commendable, you're looking at c. 1 watt difference by spinning down. An SSD will run at around 2W continuously, and be silent. – benwiggy Mar 02 '20 at 14:37
  • Thanks for your comments, but the hard drive is technically fine. It's a 3,5" disk and with noisy I mean I hear them, which is normal. Sorry if this lead to confusion. It's a 6 TB disk, so replacing it by an SSD is not an option for me. – me.at.coding Mar 02 '20 at 15:02
  • @Allan Maybe - I have to check if a drive can be sleeping when it's unused or if I have to really eject it (so Ant's answer would be fine, basically the same). Will give it a try. – me.at.coding Mar 02 '20 at 15:04
  • I hear you. However, just to "err" on the side of data protection.... I just bought 3 WD Red 6TB drives - two for the NAS (RAID) and one for the USB enclosure for backup. They're really quiet with a 5 year warranty. I'd go with a drive like that and not worry about spinning them down. (Coming from my infrastructure days), we would keep a spreadsheet of when warranties would be expiring and swap the drives out whether they needed it or not? Overkill? Perhaps, but I haven't had to use a data recovery service in at least 2 decades. – Allan Mar 02 '20 at 16:02

1 Answers1

1

You could use pmset disksleep TIME to set a timeout for the disk to go into standby mode. This way, you wouldn't have to mount/unmount the disk every time you want to access it. TIME is the time in minutes.

If you set the time to 0, the timeout is disabled, so if you want to keep it spinning you can set it to that.

Ant
  • 509