I have to figure out the physical disk number that belongs to each device in an OmniOS (Solaris 10) storage array. I can get the list of devices by

cfgadm -al | grep disk-path | cut -c 6-21 | tr 'a-z' 'A-Z'

where the output could look like

5000C5005CF65F14
5000C5004F30CC82
...

So my idea is to write a script where I dd each device and watch the leds, and then enter the number of the led that flashed. As there are leds on both sides of the storage array, I need to be able to run the script multiple times, and for each time I enter a disk location, I shouldn't have to enter it again.

My current idea is to loop over the list of device names I get from the above command and then do something like this

system("dd if=/dev/dsk/c1t${device}d0p0 of=/dev/null bs=1k count=100");
print "which led flashed: ";
my $disk = <STDIN>;
chomp $disk;
system("echo $disk $device >> disk.sorted");

which would produce lines like these

21 5000C5005CF65F14
09 5000C5004F30CC82
...

where I have seen led 21 flash in the first case and seen led 9 in the second case. There are 70 disks.

My problem

I can not come up with a good idea how I can write a script which can be run multiple times, and for each time it is run it will not destroy my previous values I have entered.

Any ideas how to do this?

I am prototyping it on Linux.

有帮助吗?

解决方案 2

Script 1

rm -f /tmp/a/*
rm -f /tmp/b/*
mkdir -p /tmp/a
mkdir -p /tmp/b

for f in $(cfgadm -al | grep disk-path | cut -c 6-21 | tr 'a-z' 'A-Z'); do touch /tmp/a/$f; done

Script 2

controller="c3t"

for f in /tmp/a/*; do
    dd if=/dev/dsk/$controller${f##*/}d0p0 of=/dev/null bs=1k count=100
    echo "Which led flashed? Press RET to skip to next"
    read n
    if ! [ -z $n ]; then echo $controller${f##*/} > /tmp/b/$n && rm -f $f; fi
done

cat /tmp/b/*

Script 3

for f in /tmp/b/*; do
    echo $f
    dd if=/dev/dsk/$(cat $f)d0p0 of=/dev/null bs=1k count=100
done

其他提示

For each run of your skript, write the output into a different file, say out.1, out.2, and so on. Afterwards run

sort -k +2 out.*

you will have all results for one disk one after another. The sort will sort the contents of all files given according to the second column, which is the disk id.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top