重写了一遍硬盘的spindown休眠脚本,增加了一个硬盘,觉得之前写的那个硬盘的spindown休眠脚本有点问题。
#!/bin/bash
if [ ! -f /dev/shm/1 ]
then
touch /dev/shm/1 /dev/shm/2
echo "$(date '+%F %T') Tempfile does not exist, creating" >> /var/log/hd_spindown.log
fi
mv /dev/shm/1 /dev/shm/2
cat /proc/diskstats > /dev/shm/1
aa=`ls -l /dev/disk/by-id |grep WDC_WD10EARS|sed '2,$d'|sed 's/^.*\///g'|grep s`
if [ ! "$aa" = "" ]
then
if [ "$(diff /dev/shm/1 /dev/shm/2 | grep $aa )" = "" ]
then
if [ "$(/sbin/hdparm -C /dev/$aa | grep "drive state" | cut -d: -f2 | awk '{ print $1}')" = "active/idle" ]
then
/sbin/hdparm -y /dev/$aa &
echo "$(date '+%F %T') $aa Spindown" >> /var/log/hd_spindown.log
else
echo "$(date '+%F %T') already spun down $aa" >> /var/log/hd_spindown.log
fi
else
echo "$(date '+%F %T') $aa is in use" >> /var/log/hd_spindown.log
fi
fi
z=`ls -l /dev/disk/by-id |grep WDC_WD10EZEX|sed '2,$d'|sed 's/^.*\///g'|grep s`
if [ ! "$z" = "" ]
then
if [ "$(diff /dev/shm/1 /dev/shm/2 | grep $z )" = "" ]
then
if [ "$(/sbin/hdparm -C /dev/$z | grep "drive state" | cut -d: -f2 | awk '{ print $1}')" = "active/idle" ]
then
/sbin/hdparm -y /dev/$z &
echo "$(date '+%F %T') $z Spindown" >> /var/log/hd_spindown.log
else
echo "$(date '+%F %T') already spun down $z" >> /var/log/hd_spindown.log
fi
else
echo "$(date '+%F %T') $z is in use" >> /var/log/hd_spindown.log
fi
fi
根据/dev/disk/by-id里硬盘的id来确定是那个硬盘, 比较精确。