New feature, updated to inxi 1.8.0, -R for RAID output.

Includes 4 levels, -b shows basic only, -R shows primary info, device id, components, state, and report on drives 

-Rx shows more, and triggers a second info line per device with more raid info.

-Rxx also adds more information, and triggers system raid support info and unmounted raid devices line.

-F uses -R now.

And that's that, enough raid stuff for a lifetime.
This commit is contained in:
inxi-svn 2012-05-11 06:01:17 +00:00
parent 4fa7edd006
commit 65aa044f30

441
inxi
View file

@ -1,8 +1,8 @@
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 1.7.36
#### Date: April 26 2012
#### version: 1.8.0
#### Date: May 10 2012
#### Patch Number: 00
########################################################################
#### SPECIAL THANKS
@ -256,6 +256,7 @@ B_SCRIPT_UP='false'
B_SHOW_ADVANCED_NETWORK='false'
# Show sound card data
B_SHOW_AUDIO='false'
B_SHOW_BASIC_RAID='false'
B_SHOW_BASIC_CPU='false'
B_SHOW_BASIC_DISK='false'
B_SHOW_BASIC_OPTICAL='false'
@ -1807,6 +1808,7 @@ get_parameters()
;;
b) use_short='false'
B_SHOW_BASIC_CPU='true'
B_SHOW_BASIC_RAID='true'
B_SHOW_DISK_TOTAL='true'
B_SHOW_GRAPHICS='true'
B_SHOW_INFO='true'
@ -1879,6 +1881,7 @@ get_parameters()
B_SHOW_MACHINE='true'
B_SHOW_NETWORK='true'
B_SHOW_PARTITIONS='true'
B_SHOW_RAID='true'
B_SHOW_SENSORS='true'
B_SHOW_SYSTEM='true'
use_short='false'
@ -1960,6 +1963,7 @@ get_parameters()
fi
if [[ $OPTARG -ge 2 ]];then
B_SHOW_BASIC_DISK='true'
B_SHOW_BASIC_RAID='true'
B_SHOW_MACHINE='true'
B_SHOW_NETWORK='true'
fi
@ -2114,6 +2118,12 @@ get_parameters()
if [[ $B_OVERRIDE_FILTER == 'true' ]];then
B_OUTPUT_FILTER='false'
fi
# change basic to full if user requested it or if arg overrides it
if [[ $B_SHOW_RAID == 'true' && $B_SHOW_BASIC_RAID == 'true' ]];then
B_SHOW_BASIC_RAID='false'
fi
eval $LOGFE
}
@ -2171,7 +2181,8 @@ show_options()
print_screen_output "-P Show Partition information (shows what -v 4 would show, but without extra data)."
print_screen_output " Shows, if detected: / /boot /home /tmp /usr /var. Use -p to see all mounted partitions."
print_screen_output "-r Show distro repository data. Currently supported repo types: APT; PACMAN; PISI; YUM."
print_screen_output "-R (COMING - NEW FEATURE) Show RAID data. Shows RAID devices and components, and extra data with -x/-xx"
print_screen_output "-R Show RAID data. Shows RAID devices, states, levels, and components, and extra data with -x/-xx"
print_screen_output " If device is resyncing, shows resync progress line as well."
print_screen_output "-s Show sensors output (if sensors installed/configured): mobo/cpu/gpu temp; detected fan speeds."
print_screen_output " Gpu temp only for Fglrx/Nvidia drivers. Nvidia shows screen number for > 1 screens."
print_screen_output "-S Show System information: host name, kernel, desktop environment (if in X), distro"
@ -2183,13 +2194,14 @@ show_options()
print_screen_output " Supported levels: 0-${VERBOSITY_LEVELS} Example: $SCRIPT_NAME -v 4"
print_screen_output " 0 - Short output, same as: $SCRIPT_NAME"
print_screen_output " 1 - Basic verbose, -S + basic CPU + -G + basic Disk + -I."
print_screen_output " 2 - Adds networking card (-N), Machine (-M) data, and shows basic hard disk data (names only)."
print_screen_output " Same as: $SCRIPT_NAME -b"
print_screen_output " 2 - Adds networking card (-N), Machine (-M) data, shows basic hard disk data (names only),"
print_screen_output " and basic raid (devices only, and if inactive, notes that). Same as: $SCRIPT_NAME -b"
print_screen_output " 3 - Adds advanced CPU (-C), network (-n) data, and switches on -x advanced data option."
print_screen_output " 4 - Adds partition size/filled data (-P) for (if present):/, /home, /var/, /boot"
print_screen_output " Shows full disk data (-D)"
print_screen_output " 5 - Adds audio card (-A); sensors (-s), partition label (-l) and UUID (-u), short form of optical drives."
print_screen_output " 6 - Adds full partition data (-p), unmounted partition data (-o), optical drive data (-d)."
print_screen_output " Shows full disk data (-D)."
print_screen_output " 5 - Adds audio card (-A); sensors (-s), partition label (-l) and UUID (-u), short form of optical drives,"
print_screen_output " standard raid data (-R)."
print_screen_output " 6 - Adds full partition data (-p), unmounted partition data (-o), optical drive data (-d), full raid."
print_screen_output " 7 - Adds network IP data (-i); triggers -xx."
print_screen_output "-x Show extra data (only works with verbose or line output, not short form): "
print_screen_output " -C - bogomips on Cpu;"
@ -2202,14 +2214,16 @@ show_options()
print_screen_output " -I - Show system GCC, default. With -xx, also show other installed GCC versions."
print_screen_output " -N -A - Adds version/port(s)/driver version (if available) for Network/Audio;"
print_screen_output " -N -A -G - Network, audio, graphics, shows PCI Bus ID/Usb ID number of card;"
print_screen_output " -R - Show RAID chunk size"
print_screen_output " -R - Shows component raid id. Adds second RAID Info line: raid level; report on drives (like 5/5);"
print_screen_output " blocks; chunk size; bitmap (if present). Resync line, shows blocks synced/total blocks."
print_screen_output " -S - Desktop toolkit if avaliable (GNOME/XFCE/KDE only); Kernel gcc version"
print_screen_output " -t - Adds memory use output to cpu (-xt c), and cpu use to memory (-xt m)."
print_screen_output "-xx Show extra, extra data (only works with verbose or line output, not short form): "
print_screen_output " -D - Adds disk serial number."
print_screen_output " -I - Adds other detected installed gcc versions to primary gcc output (if present)."
print_screen_output " -M - Adds chassis information, if any data for that is available."
print_screen_output " -R - Adds block count and algorythm used to RAID."
print_screen_output " -R - Adds superblock (if present); algorythm, U data. Adds system info line (kernel support,"
print_screen_output " read ahead, raid events). Adds if present, unused device line. Resync line, shows progress bar."
print_screen_output " -xx -@ <11-14> - Automatically uploads debugger data tar.gz file to ftp.techpatterns.com."
print_screen_output "-z Adds security filters for IP addresses, Mac, and user home directory name. Default on for irc clients."
print_screen_output "-Z Absolute override for output filters. Useful for debugging networking issues in irc for example."
@ -5452,6 +5466,154 @@ get_ps_data()
eval $LOGFE
}
# mdstat syntax information: http://www-01.ibm.com/support/docview.wss?uid=isg3T1011259
# note that this does NOT use either Disk or Partition information for now, ie, there
# is no connection between the data types, but the output should still be consistent
get_raid_data()
{
eval $LOGFS
local mdstat=''
if [[ $B_MDSTAT_FILE ]];then
mdstat="$( cat $FILE_MDSTAT )"
fi
if [[ -n $mdstat ]];then
# need to make sure there's always a newline in front of each record type, and
# also correct possible weird formats for the output from older kernels etc.
mdstat="$( sed -e 's/^md/\nmd/' -e 's/^unused[[:space:]]/\nunused /' \
-e 's/read_ahead/\nread_ahead/' -e 's/^resync=/\nresync=/' -e 's/^Event/\nEvent/' \
-e 's/^[[:space:]]*$//' -e 's/[[:space:]]read_ahead/\nread_ahead/' <<< "$mdstat" )"
# some fringe cases do not end as expected, so need to add newlines plus EOF to make sure while loop doesn't spin
mdstat=$( echo -e "$mdstat\n\nEOF" )
IFS=$'\n'
A_RAID_DATA=( $(
gawk '
BEGIN {
IGNORECASE=1
RS="\n"
}
/^personalities/ {
KernelRaidSupport = gensub(/personalities[[:space:]]*:[[:space:]]*(.*)/, "\\1", 1, $0)
# clean off the brackets
gsub(/[\[\]]/,"",KernelRaidSupport)
print "KernelRaidSupport," KernelRaidSupport
}
/^read_ahead/ {
ReadAhead=gensub(/read_ahead (.*)/, "\\1", 1 )
print "ReadAhead," ReadAhead
}
/^Event:/ {
print "raidEvent," $NF
}
# print logic will search for this value and use it to print out the unused devices data
/^unused devices/ {
unusedDevices = gensub(/^unused devices:[[:space:]][<]?([^>]*)[>]?.*/, "\\1", 1, $0)
print "UnusedDevices," unusedDevices
}
/^md/ {
# reset for each record loop through
deviceState = ""
bitmapValues = ""
blocks = ""
chunkSize = ""
components = ""
device = ""
deviceReport = ""
finishTime = ""
recoverSpeed = ""
recoveryProgressBar = ""
recoveryPercent = ""
raidLevel = ""
sectorsRecovered = ""
separator = ""
superBlock = ""
uData = ""
while ( !/^[[:space:]]*$/ ) {
gsub(/,/, " ", $0 )
gsub(/[[:space:]]+/, " ", $0 )
if ( $0 ~ /^md/ ) {
device = gensub(/(md.*)[[:space:]]?:/, "\\1", "1", $1 )
}
if ( $0 ~ /raid[0-9]+/ ) {
raidLevel = gensub(/(.*)raid([0-9]+)(.*)/, "\\2", "g", $0 )
}
if ( $0 ~ /(active \(auto-read-only\)|active|inactive)/ ) {
deviceState = gensub(/(.*) (active \(auto-read-only\)|active|inactive) (.*)/, "\\2", "1", $0 )
}
# gawk will not return all the components using gensub, only last one
separator = ""
for ( i=3; i<=NF; i++ ) {
if ( $i ~ /[hs]d[a-z][0-9]*(\[[0-9]+\])?(\([SF]\))?/ ) {
components = components separator $i
separator=" "
}
}
if ( $0 ~ /blocks/ ) {
blocks = gensub(/(.*[[:space:]]+)?([0-9]+)[[:space:]]blocks.*/, "\\2", "1", $0)
}
if ( $0 ~ /super[[:space:]][0-9\.]+/ ) {
superBlock = gensub(/.*[[:space:]]super[[:space:]]([0-9\.]+)[[:space:]].*/, "\\1", "1", $0)
}
if ( $0 ~ /algorithm[[:space:]][0-9\.]+/ ) {
algorithm = gensub(/.*[[:space:]]algorithm[[:space:]]([0-9\.]+)[[:space:]].*/, "\\1", "1", $0)
}
if ( $0 ~ /\[[0-9]+\/[0-9]+\]/ ) {
deviceReport = gensub(/.*[[:space:]]\[([0-9]+\/[0-9]+)\][[:space:]].*/, "\\1", "1", $0)
uData = gensub(/.*[[:space:]]\[([U_]+)\]/, "\\1", "1", $0)
}
# need to avoid this: bitmap: 0/10 pages [0KB], 16384KB chunk
# while currently all the normal chunks are marked with k, not kb, this can change in the future
if ( $0 ~ /[0-9]+[k] chunk/ && $0 !~ /bitmap/ ) {
chunkSize = gensub(/(.*) ([0-9]+[k]) chunk.*/, "\\2", "1", $0)
}
if ( $0 ~ /^resync=/ ) {
sub(/resync=/,"")
print "resyncStatus," $0
}
if ( $0 ~ /\[[=]*>[\.]*\].*(resync|recovery)/ ) {
recoveryProgressBar = gensub(/.*(\[[=]*>[\.]*\]).*/, "\\1",1,$0)
}
if ( $0 ~ / (resync|recovery)[[:space:]]*=/ ) {
recoveryPercent = gensub(/.* (resync|recovery)[[:space:]]*=[[:space:]]*([0-9\.]+%).*/, "\\1~\\2", 1 )
if ( $0 ~ /[[:space:]]\([0-9]+\/[0-9]+\)/ ) {
sectorsRecovered = gensub(/.* \(([0-9]+\/[0-9]+)\).*/, "\\1", 1, $0 )
}
if ( $0 ~ /finish[[:space:]]*=/ ) {
finishTime = gensub(/.* finish[[:space:]]*=[[:space:]]*([[0-9\.]+)([a-z]+) .*/, "\\1 \\2", 1, $0 )
}
if ( $0 ~ /speed[[:space:]]*=/ ) {
recoverSpeed = gensub(/.* speed[[:space:]]*=[[:space:]]*([[0-9\.]+)([a-z]+\/[a-z]+)/, "\\1 \\2", 1, $0 )
}
}
if ( $0 ~ /bitmap/ ) {
bitmapValues = gensub(/(.*[[:space:]])?bitmap:(.*)/, "\\2", 1, $0 )
}
getline
}
raidString = device "," deviceState "," raidLevel "," components "," deviceReport "," uData
raidString = raidString "," blocks "," superBlock "," algorithm "," chunkSize "," bitmapValues
raidString = raidString "," recoveryProgressBar "," recoveryPercent "," sectorsRecovered "," finishTime "," recoverSpeed
print raidString
}
' <<< "$mdstat"
) )
IFS="$ORIGINAL_IFS"
temp_array=${A_RAID_DATA[@]}
log_function_data "A_RAID_DATA: $temp_array"
# echo -e "A_RAID_DATA:\n${A_RAID_DATA[@]}"
fi
eval $LOGFE
}
# Repos will be added as we get distro package manager data to create the repo data.
# This method will output the file name also, which is useful to create output that's
# neat and readable.
@ -6219,6 +6381,9 @@ print_it_out()
if [[ $B_SHOW_PARTITIONS == 'true' ]];then
print_partition_data
fi
if [[ $B_SHOW_RAID == 'true' || $B_SHOW_BASIC_RAID == 'true' ]];then
print_raid_data
fi
if [[ $B_SHOW_UNMOUNTED_PARTITIONS == 'true' ]];then
print_unmounted_partition_data
fi
@ -7618,6 +7783,262 @@ print_ps_item()
eval $LOGFE
}
print_raid_data()
{
eval $LOGFS
local device='' device_string='' device_state='' raid_level='' device_components=''
local device_report='' u_data='' blocks='' super_blocks='' algorithm='' chunk_size=''
local bitmap_values='' recovery_progress_bar='' recovery_percent='' recovered_sectors=''
local finish_time='' recovery_speed='' raid_counter=0 device_counter=1 basic_counter=1
local a_partition_working='' raid_data='' kernel_support='' read_ahead='' unused_devices=''
local basic_raid='' basic_raid_separator='' basic_raid_plural='' inactive=''
local component_separator='' device_id='' print_string='' loop_limit='' array_count_unused=''
local array_count='' raid_event=''
get_raid_data
for (( i=0; i < ${#A_RAID_DATA[@]}; i++ ))
do
IFS=","
a_partition_working=(${A_RAID_DATA[i]})
IFS="$ORIGINAL_IFS"
# reset on each iteration
algorithm=''
bitmap_values=''
blocks=''
component_separator=''
device=''
device_components=''
device_id=''
device_report=''
device_state=''
failed=''
finish_time=''
inactive=''
raid_event=''
raid_level=''
recovery_percent=''
recovery_progress_bar=''
recovered_sectors=''
recovery_speed=''
spare=''
super_blocks=''
u_data=''
if [[ -n $( grep '^md' <<< ${a_partition_working[0]} ) ]];then
if [[ $B_SHOW_BASIC_RAID == 'true' ]];then
if [[ $basic_raid != '' ]];then
basic_raid_plural='s'
fi
if [[ ${a_partition_working[1]} == 'inactive' ]];then
inactive=" - ${a_partition_working[1]}"
fi
basic_raid="$basic_raid$basic_raid_separator${C1}$basic_counter${SEP3}${C2} /dev/${a_partition_working[0]}$inactive"
basic_raid_separator=' '
(( basic_counter++ ))
else
device_id="-$device_counter"
device="/dev/${a_partition_working[0]}"
(( device_counter++ ))
if [[ ${a_partition_working[1]} != '' ]];then
device_state=" - ${a_partition_working[1]}"
fi
if [[ ${a_partition_working[2]} == '' ]];then
raid_level='N/A'
else
raid_level=${a_partition_working[2]}
fi
# there's one case: md0 : inactive that has to be protected against
if [[ ${a_partition_working[2]} == '' && ${a_partition_working[1]} == 'inactive' ]];then
raid_level=''
else
raid_level=" ${C1}raid${SEP3}${C2} $raid_level"
fi
if [[ ${a_partition_working[4]} != '' ]];then
device_report="${a_partition_working[4]}"
fi
if [[ $B_EXTRA_DATA == 'true' ]];then
if [[ ${a_partition_working[6]} != '' ]];then
blocks=${a_partition_working[6]}
else
blocks='N/A'
fi
blocks=" ${C1}blocks${SEP3}${C2} $blocks"
if [[ ${a_partition_working[9]} != '' ]];then
chunk_size=${a_partition_working[9]}
else
chunk_size='N/A'
fi
chunk_size=" ${C1}chunk size${SEP3}${C2} $chunk_size"
if [[ ${a_partition_working[10]} != '' ]];then
bitmap_value='true'
bitmap_value=" ${C1}bitmap${SEP3}${C2} $bitmap_value"
fi
fi
if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
if [[ ${a_partition_working[5]} != '' ]];then
u_data=" ${a_partition_working[5]}"
fi
if [[ ${a_partition_working[7]} != '' ]];then
super_blocks=" ${C1}super blocks${SEP3}${C2} ${a_partition_working[7]}"
fi
if [[ ${a_partition_working[8]} != '' ]];then
algorithm=" ${C1}algorithm${SEP3}${C2} ${a_partition_working[8]}"
fi
fi
if [[ ${a_partition_working[3]} == '' ]];then
if [[ ${a_partition_working[1]} != 'inactive' ]];then
device_components='N/A'
fi
else
for component in ${a_partition_working[3]}
do
if [[ $B_EXTRA_DATA != 'true' ]];then
component=$( sed 's/\[[0-9]\+\]//' <<< $component )
fi
if [[ -n $( grep 'F' <<< $component ) ]];then
component=$( sed -e 's/(F)//' -e 's/F//' <<< $component )
failed="$failed $component"
component=''
elif [[ -n $( grep 'S' <<< $component ) ]];then
component=$( sed -e 's/(S)//' -e 's/S//' <<< $component )
spare="$spare $component"
component=''
else
device_components=$device_components$component_separator$component
component_separator=' '
fi
done
if [[ $failed != '' ]];then
failed=" ${C1}FAILED${SEP3}${C2}$failed${C2}"
fi
if [[ $spare != '' ]];then
spare=" ${C1}spare${SEP3}${C2}$spare${C2}"
fi
if [[ $device_components != '' ]];then
if [[ $B_EXTRA_DATA != 'true' ]];then
device_components="$device_report - $device_components"
fi
device_components=" ${C1}components${SEP3}${C2} $device_components$failed$spare"
fi
fi
a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$raid_level$device_components"
if [[ $B_EXTRA_DATA == 'true' && ${a_partition_working[1]} != 'inactive' ]];then
a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$device_components"
(( raid_counter++ ))
print_string="${C1}Info${SEP3}${C2}$raid_level ${C1}report${SEP}${C2} $device_report$u_data"
print_string="$print_string$blocks$chunk_size$bitmap_value$super_blocks$algorithm"
a_raid_data[$raid_counter]="$print_string"
else
a_raid_data[$raid_counter]="${C1}Device$device_id${SEP3}${C2} $device$device_state$raid_level$device_components"
fi
(( raid_counter++ ))
# now let's do the recover line if required
if [[ ${a_partition_working[12]} != '' ]];then
recovery_percent=$( cut -d '~' -f 2 <<< ${a_partition_working[12]} )
if [[ ${a_partition_working[14]} != '' ]];then
finish_time=${a_partition_working[14]}
else
finish_time='N/A'
fi
finish_time=" ${C1}time remaining${SEP3}${C2} $finish_time"
if [[ $B_EXTRA_DATA == 'true' ]];then
if [[ ${a_partition_working[13]} != '' ]];then
recovered_sectors=" ${C1}sectors${SEP3}${C2} ${a_partition_working[13]}"
fi
fi
if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
if [[ ${a_partition_working[11]} != '' ]];then
recovery_progress_bar=" ${a_partition_working[11]}"
fi
if [[ ${a_partition_working[15]} != '' ]];then
recovery_speed=" ${C1}speed${SEP3}${C2} ${a_partition_working[15]}"
fi
fi
a_raid_data[$raid_counter]="${C1}Recovering${SEP3}${C2} $recovery_percent$recovery_progress_bar$recovered_sectors$finish_time$recovery_speed"
(( raid_counter++ ))
fi
fi
elif [[ ${a_partition_working[0]} == 'KernelRaidSupport' ]];then
if [[ ${a_partition_working[1]} == '' ]];then
kernel_support='N/A'
else
kernel_support=${a_partition_working[1]}
fi
kernel_support=" ${C1}supported${SEP3}${C2} $kernel_support"
elif [[ ${a_partition_working[0]} == 'ReadAhead' ]];then
if [[ ${a_partition_working[1]} != '' ]];then
read_ahead=${a_partition_working[1]}
read_ahead=" ${C1}read ahead${SEP3}${C2} $read_ahead"
fi
elif [[ ${a_partition_working[0]} == 'UnusedDevices' ]];then
if [[ ${a_partition_working[1]} == '' ]];then
unused_devices='N/A'
else
unused_devices=${a_partition_working[1]}
fi
unused_devices="${C1}Unused Devices${SEP3}${C2} $unused_devices"
elif [[ ${a_partition_working[0]} == 'raidEvent' ]];then
if [[ ${a_partition_working[1]} != '' ]];then
raid_event=${a_partition_working[1]}
raid_event=" ${C1}Raid Event${SEP3}${C2} ${a_partition_working[1]}"
fi
fi
done
if [[ $B_SHOW_BASIC_RAID == 'true' && $basic_raid != '' ]];then
a_raid_data[0]="${C1}Device$basic_raid_plural${SEP3}${C2} $basic_raid"
fi
if [[ ${a_raid_data[0]} == '' ]];then
a_raid_data[0]="${C1}Device${SEP3}${C2} No RAID devices detected"
fi
# now let's add on the system line and the unused device line. Only print on -xx
array_count=${#a_raid_data[@]}
a_raid_data[array_count]="${C1}System${SEP3}${C2}$kernel_support$read_ahead$raid_event"
loop_limit=1
if [[ $unused_devices != '' ]];then
array_count_unused=${#a_raid_data[@]}
a_raid_data[array_count_unused]="$unused_devices"
loop_limit=2
fi
# print out all lines, line starter on first line
for (( i=0; i < ${#a_raid_data[@]} - $loop_limit;i++ ))
do
if [[ $i -eq 0 ]];then
line_starter='RAID:'
else
line_starter=' '
fi
if [[ $B_EXTRA_EXTRA_DATA == 'true' ]];then
if [[ $i == 0 ]];then
raid_data=$( create_print_line "$line_starter" "${a_raid_data[array_count]}" )
print_screen_output "$raid_data"
line_starter=' '
fi
fi
raid_data=$( create_print_line "$line_starter" "${a_raid_data[i]}" )
print_screen_output "$raid_data"
if [[ $B_EXTRA_EXTRA_DATA == 'true' && $array_count_unused != '' ]];then
if [[ $i == $(( array_count_unused - 2 )) ]];then
raid_data=$( create_print_line "$line_starter" "${a_raid_data[array_count_unused]}" )
print_screen_output "$raid_data"
fi
fi
done
eval $LOGFE
}
# currently only apt using distros support this feature, but over time we can add others
print_repo_data()