Script Archive: lunreport

!/bin/sh
 Script for matching LUNs with local device names
 Tested on Linux using open-iscsi
 Build Header
 /bin/echo "" > /var/log/lun-report.log
 /bin/echo "Node: "/bin/hostname -f >> /var/log/lun-report.log
 /bin/echo "OS:   "/bin/uname -o;/bin/uname -r >> /var/log/lun-report.log
 /bin/echo "Date: "/bin/date >> /var/log/lun-report.log
 /bin/echo "" >> /var/log/lun-report.log
 for v in /sbin/vgdisplay | /bin/grep "VG Name" | /usr/bin/awk '{print $3}';
 do
 /bin/echo "+----------" >> /var/log/lun-report.log
 /bin/echo "| "$v >> /var/log/lun-report.log;
 /bin/echo "+----------" >> /var/log/lun-report.log
 /bin/echo "" >> /var/log/lun-report.log;
 /bin/echo "Logical Volume(s): " >> /var/log/lun-report.log;
 /sbin/vgdisplay -v $v | /bin/grep "LV Name" | /usr/bin/awk '{print $3}' >> /var/log/lun-report.log
 /bin/echo "" >> /var/log/lun-report.log;
 /bin/df -h | /bin/grep Filesystem | /usr/bin/awk '{print $1"(s):"}' >> /var/log/lun-report.log;
 for m in /bin/mount | /bin/grep $v | /usr/bin/awk '{print $3}';
 do
 /bin/echo -n $m >> /var/log/lun-report.log;
 /bin/df -h $m | /bin/grep -v dev | /bin/grep -v Filesystem | /usr/bin/awk '{print "\t\tSize: "$1"\tUsed: "$2"\tAvail: "$3}' >> /var/log/lun-report.log;
 /bin/echo "" >> /var/log/lun-report.log
 done
 /bin/echo "LUN / Dev Pair(s):" >> /var/log/lun-report.log;
 for d in /sbin/vgdisplay -v $v | /bin/grep "PV Name" | /usr/bin/awk '{print $3}' | /bin/sed 's/^.\{5\}//g';
 do
 mdadm breaks this by listing md devices in vgdisplay
 /bin/ls -l /dev/disk/by-path | /bin/grep $d | /usr/bin/awk '{print $9"\t"$10"\t"$11}' >> /var/log/lun-report.log;
 /bin/ls -l /dev/disk/by-path | /usr/bin/awk '{print $9"\t"$10"\t"$11}' >> /var/log/lun-report.log;
 /bin/ls -l /dev/disk/by-path | /bin/grep $d >> /var/log/lun-report.log;
 /bin/echo "TEST!";
 /bin/echo $d;
 done
 /bin/echo "" >> /var/log/lun-report.log;
 done
 Send email notification
 /bin/cat /var/log/lun-report.log | /usr/bin/mailx email@mail.com -s "lunreport.sh: /bin/date +%m%d%Y:%H%M.%S"