

#for i in {0..29};do 
#  d=$(ls /sys/devices/pci0000:c0/0000:c0:03.1/0000:c1:00.0/host1/port-1:0/expander-1:0/port-1:0:$i/end_device-1:0:$i/target1:0:$i/1:0:$i:0/block/); 
#  echo /dev/$d;head -n 30 /dev/$d | grep -a 'device ='; 
#  find /sys/devices/ -name $d | grep port;
#  printf '\n';
#done 

#KERNEL=="sd?", SUBSYSTEM=="block", DEVPATH=="*port-1:0/expander-1:0/port-1:0:8/end_device-1:0:8*", NAME="sdl", RUN+="/usr/bin/logger My disk ATTR{partition}=$ATTR{partition}, DEVPATH=$devpath, ID_PATH=$ENV{ID_PATH}, ID_SERIAL=$ENV{ID_SERIAL}", GOTO="END_20_PERSISTENT_DISK"

#KERNEL=="sd?*", ATTR{partition}=="1", SUBSYSTEM=="block", DEVPATH=="*port-1:0/expander-1:0/port-1:0:8/end_device-1:0:8*", NAME="sdl%n" RUN+="/usr/bin/logger My partition parent=%p number=%n, ATTR{partition}=$ATTR{partition}"
#LABEL="END_20_PERSISTENT_DISK"


#KERNEL=="sd?", SUBSYSTEM=="block", DEVPATH=="*port-1:0/expander-1:0/port-1:0:0/end_device-1:0:0*", NAME="sdd", RUN+="/usr/bin/logger My disk ATTR{partition}=$ATTR{partition}, DEVPATH=$devpath, ID_PATH=$ENV{ID_PATH}, ID_SERIAL=$ENV{ID_SERIAL}", GOTO="END_20_PERSISTENT_DISK"
#KERNEL=="sd?*", ATTR{partition}=="1", SUBSYSTEM=="block", DEVPATH=="*port-1:0/expander-1:0/port-1:0:0/end_device-1:0:0*", NAME="sdd%n" RUN+="/usr/bin/logger My partition parent=%p number=%n, ATTR{partition}=$ATTR{partition}"
#LABEL="END_20_PERSISTENT_DISK"


for i in {0..29};do

d=$(ls /sys/devices/pci0000:c0/0000:c0:03.1/0000:c1:00.0/host1/port-1:0/expander-1:0/port-1:0:$i/end_device-1:0:$i/target1:0:$i/1:0:$i:0/block/);
r=$(head -n 30 /dev/$d | grep -a 'device =' | awk '{print $3}');
t="${r%\"}"
real="${t#\"}"

#echo $real

#echo ${real##*/}

echo KERNEL==\"sd?\", SUBSYSTEM==\"block\", DEVPATH==\"*port-1:0/expander-1:0/port-1:0:$i/end_device-1:0:$i*\", SYMLINK+=\"${real##*/}\", RUN+=\"/usr/bin/logger My disk ATTR{partition}=\$ATTR{partition}, DEVPATH=\$devpath, ID_PATH=\$ENV{ID_PATH}, ID_SERIAL=\$ENV{ID_SERIAL}\", GOTO=\"END_20_PERSISTENT_DISK\"

echo KERNEL==\"sd?*\", ATTR{partition}==\"1\", SUBSYSTEM==\"block\", DEVPATH==\"*port-1:0/expander-1:0/port-1:0:$i/end_device-1:0:$i*\", SYMLINK+=\"${real##*/}%n\" RUN+=\"/usr/bin/logger My partition parent=%p number=%n, ATTR{partition}=\$ATTR{partition}\" 
echo LABEL=\"END_20_PERSISTENT_DISK\"

printf "\n"

done


