Skip to content

Instantly share code, notes, and snippets.

@mqu
Created April 25, 2021 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mqu/115fdc9eb471d81ac0ef1884746faefa to your computer and use it in GitHub Desktop.
Save mqu/115fdc9eb471d81ac0ef1884746faefa to your computer and use it in GitHub Desktop.
smartdrive-ctl : bash wrapper against smartdrive to wakeup and standby drives and getting status.
#!/bin/bash
drives='sda sdb sdc sdd'
delay=60
# 60 = 5mn
# 72 = 6mn (5*72=360s)
_in_standby() {
smartctl -i -n standby $1 > /dev/null | grep -q 'Device is in STANDBY mode'
return $?
}
case "$1" in
start|wakeup)
;;
stop)
;;
standby)
# set (force) in standby mode
for d in $drives ; do
# _in_standby $d || hdparm -q -y /dev/$d
hdparm -q -y /dev/$d
done
;;
status)
# status
for d in $drives ; do
status=$(smartctl -i -n standby /dev/$d | egrep 'Device is in|Power mode')
echo "/dev/$d: $status"
done
;;
setup)
# set timeout of inactivity before shutdown in standby mode.
for d in $drives ; do
smartctl -s on /dev/$d
hdparm -q -S $delay /dev/$d
done
;;
test)
drive=/dev/sda
_in_standby /dev/sdb && echo "sda in standby"
drive=/dev/sdb
_in_standby /dev/sdb && echo "sdb in standby"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment