Today I wrote a script to get all the usual info about a drive, format
it into an org-mode outline, and append it to a file suitable for my git
repo of notes. The top level headings have the serial number, which
Western Digital conveniently stamps on the front of its drives, so I can
easily match this data up with a drive in a machine, on a desk, or on a
shelf. I just ran it on six drives. So convenient when swapping drives
around, don't you think? Feel free to critique my bash, make a
suggestion, etc.

Please be careful my friends, it's your data, no warranty, etc.!

Usage is like:

$ sudo ./drive-notes /dev/sda

#!/bin/bash

function addsection
{
  echo "** ${1}" >> ${FILE}
  echo "#+BEGIN_EXAMPLE" >> ${FILE}
  echo "`${1}`" >> ${FILE}
  echo "#+END_EXAMPLE" >> ${FILE}
}

OWNER="${SUDO_UID}:${SUDO_GID}"
DATE="`date +"%Y-%m-%d"`"
SERIAL="`hdparm -I ${1} | sed -n '/Serial
Number:/s/.*:[[:space:]]*\([[:graph:]]*\)/\1/p'`"

# One file per drive:
#FILE="${SERIAL}.org"
# Or all in one file (it very easy to ignore structure in an org file,
so this is probably best):
FILE="notes.org"

echo "* [${DATE}]" ${SERIAL} ${1} >> ${FILE}
chown ${OWNER} ${FILE}
addsection "uname -a"
addsection "lsblk ${1}"
addsection "hdparm -I ${1}"
addsection "smartctl -i ${1}"
addsection "smartctl -l xerror ${1}"
addsection "smartctl -l xselftest ${1}"
addsection "smartctl -l ssd ${1}"
addsection "fdisk -l ${1}"
addsection "lsblk ${1}"
addsection "lsblk --fs ${1}"

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to