Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- # Check for idle disks and spin them down
- # run this from cron every 30 mins
- # */30 * * * * /usr/local/bin/spindown.sh
- # -- craiger, parts taken from Zack Reed
- # space separated list of disk wwn names to monitor.
- # These should be found in /dev/disk/by-id:
- DISKNAMES="wwn-0x5000cca222d23f5f "
- export PATH=$PATH:/sbin:/usr/sbin
- # Create a file on the ramdisk and cycle it to test for disk activity
- ( if [ ! -f /dev/shm/1 ] ; then touch /dev/shm/1 /dev/shm/2; fi ; mv /dev/shm/1 /dev/shm/2; cat /proc/diskstats > /dev/shm/1 ) >/dev/null 2>&1
- date
- # convert disk wwn id's into sdX names because kernel developers
- # think they're so clever and randomize sd* names at boot, while most
- # userspace tools assume they're static, including /proc/diskstats
- for id in $DISKNAMES
- do
- SDLIST="$SDLIST `readlink /dev/disk/by-id/$id | cut -d/ -f3`"
- done
- # Loop through all disks and spin them down if idle.
- for disk in $SDLIST
- do
- # Check if disk exists
- if [ -e /dev/$disk ]; then
- # Check if disk is currently spinning
- if [ "$(hdparm -C /dev/$disk | grep state)" = " drive state is: active/idle" ]; then
- #Check if disk has been accessed since last time
- if [ "$(diff /dev/shm/1 /dev/shm/2 | grep $disk )" = "" ]; then
- echo "Drive $disk is spun up and idle. Spinning down now."
- hdparm -y /dev/$disk
- else
- echo "Drive $disk is spun up and being accessed. No change."
- fi
- else
- echo "Drive $disk is already spun down. No change."
- fi
- else
- echo "Drive $disk not found." #will never happen
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement