Certain HDD enclosures do not allow for putting the drive in stand-by mode automatically. Fortunately you can run a script to spin down the drive periodically. If the drive is in use then it will spin down for just a moment. If the drive is in stand-by mode already, nothing will happen.
Purpose of the script
As the name suggests, it puts an HDD drive in stand-by mode (spin down). This script is useless for SSD drives as they do not need to be spanned down.
Additional packages required
- hdparm
Run the following code
sudo apt install hdparm
Spin down script code
#!/bin/bash
sudo hdparm -y /dev/sda
sudo hdparm -y /dev/sdb
sudo hdparm -y /dev/sdc
Each drive should have its own line and it should point to the drive and not to a partition of a drive.
Remember to amend the script to reflect your devices.
In order to run the script periodically use cron. Frequency should be set in accordance with your needs, if you use the drive frequently then set it to run every two or three hours.
NOTE if you are using the HDD at the moment the script is executed (e.g. watching a movie), you might notice a short slowdown or stutter when the script is executed.