Can we do something like this in a script (preferably zsh):
smartctl -t long /dev/sda
smartctl -t long /dev/sdb
smartctl -t long /dev/sdc
[Wait however long smartctl needs]
smartctl -H /dev/sda
smartctl -H /dev/sdb
smartctl -H /dev/sdc
很明显,我只是想自动化这一点。
答案1
有两种可能性。smartctl -c
将列出设备的功能,其中包括诸如
Short self-test routine
recommended polling time: ( 1) minutes.
Extended self-test routine
recommended polling time: ( 48) minutes.
因此,您只需阅读这些内容,然后按照需要的短时间或长时间睡眠即可。
其次,当测试正在进行时,相同的-c
选项将列出任何测试的当前状态,例如:
Offline data collection status: (0x03) Offline data collection activity
is in progress.
Self-test execution status: ( 247) Self-test routine in progress...
70% of test remaining.
Total time to complete Offline
data collection: ( 44) seconds.
因此,您可以每隔几分钟轮询一次,并等待剩余时间返回到 0,并且其他字段都有其最终值:
Offline data collection status: (0x02) Offline data collection activity
was completed without error.
Self-test execution status: ( 0) The previous self-test routine completed
without error or no self-test has ever
been run.
Total time to complete Offline
data collection: ( 0) seconds.
答案2
它不漂亮,但这似乎有效。可以轻松修改以处理任意数量的磁盘。欢迎模组。
#!/usr/bin/zsh
#set -x
outputmsg () { echo -e "\e[35;1m$@\e[0m"; }
infomsg () { echo -e "\e[36;1m$@\e[0m"; }
smartctl -X /dev/sda &> /dev/null
wait_time_greatest=$( smartctl -t short /dev/sda | grep 'Please wait' | sed 's,^\(Please wait \)\([[:digit:]]*\)\(.*\),\2,' )
smartctl -X /dev/sdb &> /dev/null
wait_time_new=$( smartctl -t short /dev/sdb | grep 'Please wait' | sed 's,^\(Please wait \)\([[:digit:]]*\)\(.*\),\2,' )
[ "$wait_time_new" -gt "$wait_time_greatest" ] && wait_time_greatest="$wait_time_new"
wait_time_greatest=$((wait_time_greatest + 1)) #To be safe?
infomsg "\nWe'll be done in $wait_time_greatest minutes ...\n"
sleep "$[wait_time_greatest]m"
outputmsg "Disk sda:" # Strange that the report doesn't contain the disk ID.
echo -e \e[0m # Must reset the color!
smartctl -H /dev/sda
outputmsg "Disk sdb:"
echo -e \e[0m # Must reset the color!
smartctl -H /dev/sdb
# Because smartctl seems to screw this up and it needs to be redone:
hdparm -S60y /dev/sda
hdparm -S60y /dev/sdb