script pro detekci chyb disku - preklad kodu
Jan Dušátko
jan at dusatko.org
Wed Dec 21 14:41:49 CET 2016
Ahoj,
prikladam script, u ktereho jsem prosil Dana o radu ... a rada byla tak
podrobna, ze je to script ... ;o)
Kazdopadne spouste z vas se muze hodit, potrebny soubor asc-num.txt je
mozne stahnout ze stranek http://www.t10.org/lists/asc-num.txt
Danovi velke diky
Honza
Vlastní script:
===============
#!/bin/sh
ASCQF=./asc-num.txt
# je ASC(Q) vendor-specific ?
# $1 je ASC(Q)
isVS() {
case $1 in
0?|1?|2?|3?|4?|5?|6?|7?)
false ;;
esac
}
# kanonizuje hotnotu promenne tak, aby to bylo hexadecimalni cislo se
stanovenym poctem cifer, hexa znaky jsou velka pismena
# $1 - pozadovany pocet cifer
# $2 - jmeno (! nikoliv hodnota!) promenne, jejiz obsah se ma kanonizovat
canonize() {
local C LINE
C=$( eval /bin/echo -n "00\$$2" )
LINE=$( /bin/echo "$C" | /usr/bin/sed
'y/abcdef/ABCDEF/;s/^0*\(.\{'"$1",'\}\)$/\1/' )
eval $2='$LINE'
}
# interpretuje ASC/ASCQ do textu, ktery ulozi do urcene promenne
# resi i vendor specific a unknown hodnoty
# #1 - nazev promenne do ktere ma prijit vysledek
# $2 - ASC
# $3 - ASCQ
findasc() {
local ASC ASCQ LINE
ASC="${2:-??}"
canonize 2 ASC
ASCQ="${3:-??}"
canonize 2 ASCQ
LINE=$( /usr/bin/sed -n "s/^${ASC}h\/${ASCQ}h .\{13\} //p" "$ASCQF" )
if [ -z "$LINE" ] ; then
LINE=$( /usr/bin/sed -n "s/^${ASC}h\/NNh .\{13\} //p" "$ASCQF"
| sed "s/[[:<:]]NN[[:>:]]/${ASCQ}h/g" )
fi
if [ -z "$LINE" ] && ( isVS "$ASC" || isVS "$ASCQ" ) ; then
LINE="Vendor specific ASC/ASCQ=${ASC}h/${ASCQ}h"
fi
if [ -z "$LINE" ] ; then
LINE="Unknown ASC/ASCQ=${ASC}h/${ASCQ}h"
fi
eval $1='$LINE'
return 0
}
# interpretuje SENSE KEY do textu, ktery ulozi do urcene promenne
# resi i unknown hodnoty
# #1 - nazev promenne do ktere ma prijit vysledek
# $2 - SENSE KEY
findsk() {
local SK LINE
SK="${2:-??}"
canonize 1 SK
case $SK in
0) LINE="NO SENSE";;
1) LINE="RECOVERED ERROR";;
2) LINE="NOT READY";;
3) LINE="MEDIUM ERROR";;
4) LINE="HARDWARE ERROR";;
5) LINE="ILLEGAL REQUEST";;
6) LINE="UNIT ATTENTION";;
7) LINE="DATA PROTECT";;
8) LINE="BLANK CHECK";;
9) LINE="VENDOR SPECIFIC";;
A) LINE="COPY ABORTED";;
B) LINE="ABORTED COMMAND";;
D) LINE="VOLUME OVERFLOW";;
E) LINE="MISCOMPARE";;
F) LINE="COMPLETED";;
esac
if [ -z "$LINE" ] ; then
LINE="Reserved SENSE KEY ${SK}h"
fi
eval $1='$LINE'
return 0
}
findsk STRK $1
findasc STRA $2 $3
echo "SENSE KEY: ${STRK}"
echo "ASC/ASCQ: ${STRA}"
return 0
--
Jan Dušátko
Phone: +420 602 427 840
e-mail: jan at dusatko.org
SkypeID: darmodej
GPG: http://www.dusatko.org/downloads/jdusatko.asc
More information about the Users-l
mailing list