Would you consider adding support for pool names, perhaps by getting a list of partition UUIDs from ‘zpool status’ then creating a disk group by looking up those UUIDs in /dev/disk/by-partuuid?
That would allow a more simple use of…
hdd_spin_down 600 ‘pool-usb-backups; pool-cold-storage’
…without needing to worry about finding the identifiers or disks having a different /dev/sdX over time.
I’m not interested in spindown but i was still curious… I’m not so confident in bash scripting, so i can be totally wrong and in case i will apologize in advance xD but to me not seems that the script doing that
to me seems more that the script check the disks into the group
...
if [ "$state" != "standby" ]; then
disks_idle_ok+=("$d")
but at the end will launch the command for every disks
...
if [ ${#disks_idle_ok[@]} -gt 0 ]; then
cmd="/usr/sbin/hdparm -y $(printf '%s ' "$(for d in "${disks_idle_ok[@]}"; do get_disk_path "$d"; done)")"
log "All idle disks > $THRESHOLD s. Running: $cmd"
Insults in another language, thats clever! If only I could translate that. Look, the script does not work for me. Maybe it will work for someone else but I’d rather use something that isnt AI generated. Good luck with your script.
You are right about the group logic; it was broken:
If even one disk in the group was active, the script should have skipped the entire group, but it didn’t; it, instead, kept adding the disks individually.
Thank you very much; your comment helped me fix the logic properly. It has been updated on GitHub.
if you wanna ear my 2 cents, about another little thing i see, i would also consider to be a bit more conservative there:
...
for d in "${valid_disks[@]}"; do
disk_statfile="$TMPDIR/${d}_io"
io=$(read_io "$d")
if [ $? -ne 0 ]; then
continue
fi
...
if something goes wrong, i would instead lock the spin-down of the group and show a properly log. This is IMHO more coerent with a group logic, so more a stile decision than an error/bug