Here is a small program that do just that. It works perfectly under Fedora 13. Copy/Past the text in file called /usr/bin/lshdd
#!/bin/bash
if [ "$1" == "-v" ]; then
verbose="true"
else
verbose="false"
fi
lshal | awk -v verbose=$verbose 'BEGIN {
name=""
}
{
if ($0~"^udi = ") {name=""}
if ($0~"^udi = ./org/freedesktop/Hal/devices/storage_serial_.*") {
match($3, "/org/freedesktop/Hal/devices/storage_serial_(.*).", arr);
name=arr[1]
}
if ($0~"^udi = ./org/freedesktop/Hal/devices/storage_model.*") {
match($3, "/org/freedesktop/Hal/devices/storage_model_(.*).", arr);
name=arr[1]
}
if (name!="" && $0~"block.device") {
match($3, "(/dev/.*).", arr);
if (verbose~"true") {
print arr[1] " = " name
} else {
print arr[1]
}
name = ""
}
}'
Change the file permissions:if [ "$1" == "-v" ]; then
verbose="true"
else
verbose="false"
fi
lshal | awk -v verbose=$verbose 'BEGIN {
name=""
}
{
if ($0~"^udi = ") {name=""}
if ($0~"^udi = ./org/freedesktop/Hal/devices/storage_serial_.*") {
match($3, "/org/freedesktop/Hal/devices/storage_serial_(.*).", arr);
name=arr[1]
}
if ($0~"^udi = ./org/freedesktop/Hal/devices/storage_model.*") {
match($3, "/org/freedesktop/Hal/devices/storage_model_(.*).", arr);
name=arr[1]
}
if (name!="" && $0~"block.device") {
match($3, "(/dev/.*).", arr);
if (verbose~"true") {
print arr[1] " = " name
} else {
print arr[1]
}
name = ""
}
}'
chmod a+x /usr/bin/lshdd
Then you can list your hard & dvd drives:lshdd -v
and the output looks like:/dev/sr0 = DVD__RW_TS_L632D
/dev/sdb = WDC_WD50_00AAVS_00ZTB0_D577A3503523_0_0
/dev/sda = SAMSUNG_HM400LI_S1PSJ10Q710844
/dev/sdb = WDC_WD50_00AAVS_00ZTB0_D577A3503523_0_0
/dev/sda = SAMSUNG_HM400LI_S1PSJ10Q710844
You can easily find the partitions of specific drive
fdisk -l /dev/sdb
P.S. It is my first awk script, so it really looks ugly, I know ;-)
No comments:
Post a Comment