- for d in $scsidevs; do
- if [[ -L "$d" ]]; then
- echo "Device $d specified by alias. Will 'readlink' for device name"
- d=$(readlink -f $d)
- fi
- devs[$i]=`sg_map | awk "{if (\\\$2 == \"$d\") print \\\$1}"`
- if [ -z "${devs[i]}" ]; then
- echo "Can't find SG device for $d, testing for partition"
- pt=`echo $d | sed 's/[0-9]*$//'`
- # Try again
- devs[$i]=`sg_map | awk "{if (\\\$2 == \"$pt\") print \\\$1}"`
- if [ -z "${devs[i]}" ]; then
- echo -e "Can't find SG device $pt.\nDo you have the sg module configured for your kernel?"
- exit 1
- fi
+ for ((i=0; i < $ndevs; i++)); do
+ # resolve symbolic link if any
+ devs[$i]=$(remote_shell ${hosts[$i]} readlink -f ${devs[$i]})
+
+ # retrieve associated sg device
+ # we will test for a LUN, the test for a partition
+ # if the partition number is > 9 this will fail
+ tmp=$(remote_shell ${hosts[$i]} sg_map | \
+ awk -v dev=${devs[$i]} '{if ($2 == dev) print $1}')
+ if [ -z "$tmp" ]; then
+ echo "Can't find SG device for ${hosts[$i]}:${devs[$i]}, " \
+ "testing for partition"
+ pt=`echo ${devs[$i]} | sed 's/[0-9]*$//'`
+ # Try again
+ tmp=$(remote_shell ${hosts[$i]} sg_map | \
+ awk -v dev=$pt '{if ($2 == dev) print $1}')
+ if [ -z "$tmp" ]; then
+ echo -e "Can't find SG device ${hosts[$i]}:$pt.\n" \
+ "Do you have the sg module configured for your kernel?"
+ exit 1
+ fi