#!/usr/bin/perl # This was meant to be run under tcpserver and to be fed a disk name from tcpclient # but you can run it directly with: # echo "diskname" | diskinfo # example: # echo sda | diskinfo # Version info: # 1.0 2004-12-24 Initial release. $OS=`uname -s`; $StrangeDisk=<>; chomp $OS; chomp $StrangeDisk; # security check... # This is running as root and using user supplied data on the command line so I have to be carefull. $Disk=$StrangeDisk; $Disk =~ s/^(...).*/$1/g; $DiskType=$Disk; $DiskType =~ s/^(..).*/$1/g; # now I know that $Disk is only 3 chars and I will verify that they are the name of a disk... if ($DiskType ne "sd") { if ($DiskType ne "hd") { if ($DiskType ne "wd") { die "ERROR: I do not recognize that type of disk.\n" } } } if ($OS eq "OpenBSD") { print "===Disk Info for $Disk===\n"; print "Partition table:\n"; system ("fdisk $Disk"); print "\nDisk label:\n"; system ("disklabel $Disk"); print "\nMounted filesystems:\n"; open (DF, "gdf -hlTP |"); while () { $Line=$_; if ($Line =~ /\/dev\/$Disk/) { print $Line; } if ($Line =~ /^Filesystem/) { print $Line; } } close (DF); } if ($OS eq "Linux") { # This is really supposed to be $3Ware but that isn't legal in perl :\ $Eware="N"; print "===Disk Info for $Disk===\n"; print "Hardware info:\n"; open (SMART, "smartctl -i /dev/$Disk|"); while () { $Line=$_; if ($Line =~ /^Device Model:/ ) { print $Line; } if ($Line =~ /^Serial Number:/ ) { print $Line; } if ($Line =~ /^Firmware Version:/ ) { print $Line; } if ($Line =~ /^ATA Version is:/ ) { print $Line; } if ($Line =~ /^ATA Standard is:/ ) { print $Line; } if ($Line =~ /^Device:/ ) { print $Line; } if ($Line =~ /^Device type:/ ) { print $Line; } if ($Line =~ /^Device: 3ware/ ) { if ($Line =~ /Logical Disk/ ) { #$Eware="Y"; $Eware=$Line; $Eware =~ s/.*Logical Disk (.).*/$1/g; chomp $Eware; } } } close (SMART); print "\nS.M.A.R.T status:\n"; open (SMART, "smartctl -a /dev/$Disk|"); while () { $Line=$_; if ($Line =~ /^SMART Health Status:/ ) { print $Line; } if ($Line =~ /^Current Drive Temperature:/ ) { print $Line; } if ($Line =~ /^SMART overall-health self-assessment test result:/ ) { print $Line; } if ($Line =~ /^194 / || $Line =~ /^198/ || $Line =~ /^ 5/ ) { $Line =~ s/^ +//; @Data=split (/ +/,$Line); ($junk,$FieldName,$junk,$junk,$junk,$junk,$junk,$junk,$State,$FieldValue)=@Data; $FieldName =~ s/read:/Read Errors/; $FieldName =~ s/write:/write Errors/; chomp $FieldValue ; if ($FieldName eq "Reallocated_Sector_Ct") { if ($State eq "-") { $State="PASSED"; } print "$FieldName: $State ($FieldValue)\n"; } else { print "$FieldName: $FieldValue\n"; } } if ( $Line =~ /^read:/ || $Line =~ /^write:/ ) { @Data=split (/ +/,$Line); ($FieldName,$junk,$junk,$junk,$junk,$junk,$junk,$FieldValue)=@Data; $FieldName =~ s/read:/Read Errors/; $FieldName =~ s/write:/write Errors/; print "$FieldName: $FieldValue"; } } close (SMART); if ($Eware ne "N") { print "\n3Ware info:\n"; open (EW, "tw_cli info |"); while () { $Line=$_; if ($Line =~ /^Controller/) { $Controller=$Line; $Controller =~ s/^Controller (.).*/$1/g; chomp $Controller; } } close (EW); system ("tw_cli info c$Controller u$Eware"); } print "\nPartition table:\n"; system ("fdisk -l /dev/$Disk"); print "\nRAID volumes:\n"; @Raids=(); open (PARTITIONS, "/proc/partitions"); while () { $PartitionInfo=$_; chomp $PartitionInfo; $PartitionInfo =~ s/^ +//; $PartitionInfo =~ s/ +/ /g; ($junk,$junk,$junk,$Partition) = split (/ /, $PartitionInfo,4); if ($Partition =~ /$Disk./) { open (LSRAID, "lsraid -A -d /dev/$Partition 2>\&1 |"); while () { if ($_ =~ /^.dev/) { print $_; }; if ($_ =~ /dev.md/) { $Line=$_; $Line =~ s/^ +//; $Line =~ s/ +/ /g; ($junk,$junk,$junk,$MD,$junk)=split (/ /,$Line,5); $MD =~ s/\/dev\///; push (@Raids, $MD); } } close (LSRAID); } } close (PARTITIONS); print "\nMounted filesystems:\n"; open (DF, "df -hlPT |"); while () { $Line=$_; if ($Line =~ /\/dev\/$Disk/) { print $Line; } if ($Line =~ /^Filesystem/) { print $Line; } if ($Line =~ /^\/dev\/mapper\/c$Disk/) { print $Line; } foreach $MD (@Raids) { if ($Line =~ /$MD/) { print $Line; } else { $Line2=$Line; $Line2 =~ s/md\//md/; if ($Line2 =~ /$MD/) { print $Line; } } } } close (DF); }