#! /bin/bash # # Examine specific system host devices to identify the drives attached # function describe_controller () { local device driver modprefix serial slotname driver="`readlink -f \"$1/driver\"`" driver="`basename $driver`" modprefix="`cut -d: -f1 <\"$1/modalias\"`" echo "Controller device @ ${1##/sys/devices/} [$driver]" if [[ "$modprefix" == "pci" ]] ; then slotname="`basename \"$1\"`" echo " `lspci -s $slotname |cut -d\ -f2-`" return fi if [[ "$modprefix" == "usb" ]] ; then if [[ -f "$1/busnum" ]] ; then device="`cat \"$1/busnum\"`:`cat \"$1/devnum\"`" serial="`cat \"$1/serial\"`" else device="`cat \"$1/../busnum\"`:`cat \"$1/../devnum\"`" serial="`cat \"$1/../serial\"`" fi echo " `lsusb -s $device` {SN: $serial}" return fi echo -e " `cat \"$1/modalias\"`" } function describe_device () { local empty=1 while read device ; do empty=0 if [[ "$device" =~ ^(.+/[0-9]+:)([0-9]+:[0-9]+:[0-9]+)/block[/:](.+)$ ]] ; then base="${BASH_REMATCH[1]}" lun="${BASH_REMATCH[2]}" bdev="${BASH_REMATCH[3]}" vnd="$(< ${base}${lun}/vendor)" mdl="$(< ${base}${lun}/model)" sn="`sginfo -s /dev/$bdev | \ sed -rn -e \"/Serial Number/{s%^.+' *(.+) *'.*\\\$%\\\\1%;p;q}\"`" &>/dev/null if [[ -n "$sn" ]] ; then echo -e " $1 `echo $lun $bdev $vnd $mdl {SN: $sn}`" else echo -e " $1 `echo $lun $bdev $vnd $mdl`" fi else echo -e " $1 Unknown $device" fi done [[ $empty -eq 1 ]] && echo -e " $1 [Empty]" } function check_host () { local found=0 local pController= while read shost ; do host=`dirname "$shost"` controller=`dirname "$host"` bhost=`basename "$host"` if [[ "$controller" != "$pController" ]] ; then pController="$controller" describe_controller "$controller" fi find $host -regex '.+/target[0-9:]+/[0-9:]+/block[:/][^/]+' |describe_device "$bhost" done } find /sys/devices/ -name 'scsi_host*' |check_host