Hello,

On Wed, 31 Jul 2013, Paul Hartman wrote:
>http://serverfault.com/questions/244944/linux-ata-errors-translating-to-a-device-name

All flawed IMHO. My version (works with PATA too), possibly flawed too:

==== ~/bin/ataid_to_drive.sh ====
#!/bin/bash
oIFS="$IFS"
IFS=$'\n'
CTRLS=( $(/sbin/lspci | grep 'ATA\|IDE') )
IFS="$oIFS"
for arg; do
    if test -z "${arg/ata*}"; then
        arg="${arg/ata}"
    fi
    if test -z "${arg/*.*}"; then
        ata="${arg%.*}"
        subid="$(printf "%i" "${arg##*.}")"
    else
        ata="$arg"
    fi
    echo "ata${ata}${subid/*/.$(printf "%02i" $subid)} is:"
    for ctrl in ${CTRLS[@]%% *}; do
        idpath="/sys/bus/pci/devices/*${ctrl}/*/*/*/unique_id"
        grep "^${ata}$" $idpath 2>/dev/null
        host=$(grep "^${ata}$" $idpath 2>/dev/null | \
               sed 's@.*/host\([0-9A-Fa-f]\+\)/.*@\1@')
        if test -n "$host"; then
            dmesg | grep "\] s[dr] $host:0:$subid.*Attached"
        fi
    done
done
====

Usage samples:

$ ataid_to_drive.sh ata23.00
$ ataid_to_drive.sh ata23.01
$ ataid_to_drive.sh ata23
$ ataid_to_drive.sh 23.01
$ ataid_to_drive.sh 23.1
$ ataid_to_drive.sh 23
$ ataid_to_drive.sh $(seq 1 4)

So you can use c&p from dmest/syslog or enter the number(s) yourself.

HTH,
-dnh

-- 
This space intentionally left aligned.

Reply via email to