functionget_release()
{
whilereadi
do
release=`echo"$i"|grep"release"|awk{print$3;}`
main_version=${release:0:1}
if[!-z$main_version]
then
echo$main_version
return0
fi
done<"/etc/redhat-release"
return1
}
functionget_id_serial()
{
device=$1;
if[-z"$device"]
then
return-1
fi
device=`basename$device`
main_version=`get_release`
if[$?-ne0]
then
echo"getcentosreleaseversionerror"1>&2
return$?
fi
case$main_versionin
"5")cmd="/usr/bin/udevinfo-qall-n$device";;
"6")cmd="/sbin/udevadminfo--query=all--name=$device";;
esac
ID_SERIAL=$($cmd|grep"ID_SERIAL="|awk-F={print$2;})
if[-z$ID_SERIAL]
then
return1
fi
echo-n"$ID_SERIAL"
return0
}
diskctl_config="/etc/udev/rules.d/99-hd.rules"
rm-rf$diskctl_config
diskctl_db="/usr/diskctl/diskctl.db"
rm-rf$diskctl_db
mkdir-p/usr/diskctl
touch$diskctl_db
index=0
foriin/dev/sd*[a-z]
do
device=`basename$i`
ID_SERIAL=`get_id_serial$i`
if[$?-ne0]
then
echo"FATAL:getID_SERIALerror"1>&2
exit1
fi
slot=`printf"slot%02d"$index`
echo"KERNEL=="sd*[a-z]",ACTION=="add",ENV{ID_SERIAL}=="$ID_SERIAL",SYMLINK+="$slot"">>$diskctl_config
echo"KERNEL=="sd*[0-9]",ACTION=="add",ENV{ID_SERIAL}=="$ID_SERIAL",SYMLINK+="$slot-part%n"">>$diskctl_config
echo"KERNEL=="sd*[a-z]",ACTION=="remove",ENV{ID_SERIAL}=="$ID_SERIAL",RUN+="/bin/rm-f/dev/$slot/dev/$slot-part*"">>$diskctl_config
echo"#split$ID_SERIAL#############################">>$diskctl_config
ID_SN=`smartctl-i$i2>/dev/null|grep"Serials*number"-i|awk{print$3;}`
if[-z"$ID_SN"]
then
ID_SN="error"
fi
echo"$slot$ID_SERIAL$ID_SN">>$diskctl_db
((index=index+1))
Done
/sbin/udevcontrolreload_rules
/sbin/start_udev