diff --git a/adaptec-raid.sh b/adaptec-raid.sh index 457776f..e4d1193 100644 --- a/adaptec-raid.sh +++ b/adaptec-raid.sh @@ -21,14 +21,15 @@ action=$1 part=$2 LLDControllers() { - ctrl_count=$($cli GETCONFIG 1 AL | grep "Controllers found:" | cut -f2 -d":" | sed -e 's/^ //' ) + ctrl_count=$($cli GETCONFIG | grep "Controllers found:" | cut -f2 -d":" | xargs ) i=1 ctrl_json="" while [ $i -le $ctrl_count ] do - ctrl_model=$($cli GETCONFIG $i AD | grep "Controller Model" | cut -f2 -d":" | sed -e 's/^ //' ) - ctrl_sn=$($cli GETCONFIG $i AD | grep "Controller Serial Number" | cut -f2 -d":" | sed -e 's/^ //' ) + ctrl_query=$($cli GETCONFIG $i AD) + ctrl_model=$(grep "Controller Model" <<< "$ctrl_query" | cut -f2 -d":" | xargs ) + ctrl_sn=$(grep "Controller Serial Number" <<< "$ctrl_query" | cut -f2 -d":" | xargs ) ctrl_info="{\"{#CTRL.ID}\":\"$i\",\"{#CTRL.MODEL}\":\"$ctrl_model\",\"{#CTRL.SN}\":\"$ctrl_sn\"}," ctrl_json=$ctrl_json$ctrl_info @@ -36,8 +37,7 @@ LLDControllers() { i=$((i+1)) done - ctrl_json=$(echo $ctrl_json | sed -e 's/,$//') - lld_data="{\"data\":[$ctrl_json]}" + lld_data="{\"data\":[${ctrl_json::-1}]}" echo $lld_data } @@ -45,17 +45,18 @@ LLDControllers() { LLDBattery() { # No controllers with battery on Linux machine # NEED SIMULATE - ctrl_count=$($cli GETCONFIG 1 AL | grep "Controllers found:" | cut -f2 -d":" | sed -e 's/^ //' ) + ctrl_count=$($cli GETCONFIG | grep "Controllers found:" | cut -f2 -d":" | xargs ) i=1 bt_json="" while [ $i -le $ctrl_count ] do - #ctrl_bt=$($cli GETCONFIG $i AD | grep "Controller Battery Information" ) + bt_query=$($cli GETCONFIG $i AD) + ctrl_bt=$(grep "Controller Battery Information" <<< "$bt_query") len=${#ctrl_bt} if [ $len -ne 0 ] then - bt_status=$($cli GETCONFIG $ctrl_id AD | grep -E "^\s+Status\s+[:]" | cut -f2 -d":" | sed -e 's/^ //' ) + bt_status=$(grep -E "^\s+Status\s+[:]" <<< "$bt_query" | cut -f2 -d":" | xargs ) len=${#bt_status} if [ $len -ne 0 ] then @@ -66,30 +67,27 @@ LLDBattery() { i=$((i+1)) done - bt_json=$(echo $bt_json | sed -e 's/,$//') - lld_data="{\"data\":[$bt_json]}" + lld_data="{\"data\":[${bt_json::-1}]}" - echo $lld_data - - #echo "{\"data\":[]}" + echo $lld_data + } LLDLogicalDrives() { - ctrl_count=$($cli GETCONFIG 1 AL | grep "Controllers found:" | cut -f2 -d":" | sed -e 's/^ //' ) + ctrl_count=$($cli GETCONFIG | grep "Controllers found:" | cut -f2 -d":" | xargs ) i=1 ld_json="" while [ $i -le $ctrl_count ] do - ld_count=$($cli GETCONFIG $i AD | grep "Logical devices/Failed/Degraded" | cut -f2 -d":" | cut -f1 -d"/" | sed -e 's/^ //' ) - - ld_ids=$($cli GETCONFIG $i LD | grep "Logical device number " | cut -f4 -d" " | sed -e 's/^ //' ) + ld_ids=$($cli GETCONFIG $i LD | grep "Logical Device number " | cut -f4 -d" " | xargs ) for ld_id in $ld_ids; do - ld_name=$($cli GETCONFIG $i LD $ld_id | grep "Logical device name" | cut -f2 -d":" | sed -e 's/^ //' ) - ld_raid=$($cli GETCONFIG $i LD $ld_id | grep "RAID level" | cut -f2 -d":" | sed -e 's/^ //' ) + ld_query=$($cli GETCONFIG $i LD $ld_id) + ld_name=$(grep "Logical Device name" <<< "$ld_query" | cut -f2 -d":" | xargs ) + ld_raid=$(grep "RAID level" <<< "$ld_query" | cut -f2 -d":" | xargs ) - if [ "$ld_name" = "" ] + if [[ "$ld_name" = "" ]] then ld_name=$ld_id fi @@ -101,21 +99,21 @@ LLDLogicalDrives() { i=$((i+1)) done - ld_json=$(echo $ld_json | sed -e 's/,$//') - lld_data="{\"data\":[$ld_json]}" + lld_data="{\"data\":[${ld_json::-1}]}" echo $lld_data } LLDPhysicalDrives() { - ctrl_count=$($cli GETCONFIG 1 AL | grep "Controllers found:" | cut -f2 -d":" | sed -e 's/^ //' ) + ctrl_count=$($cli GETCONFIG | grep "Controllers found:" | cut -f2 -d":" | xargs ) i=1 pd_json="" while [ $i -le $ctrl_count ] do - pd_list=($($cli GETCONFIG $i PD | grep "Device #" | cut -f2 -d"#" )) - pd_list_type=($($cli GETCONFIG 1 PD | grep 'Device is a' | sed -e 's/ /_/g')) + pd_query=$($cli GETCONFIG $i PD) + pd_list=($(grep "Device #" <<< "$pd_query" | cut -f2 -d"#" )) + pd_list_type=($(grep 'Device is a' <<< "$pd_query" | sed -e 's/ /_/g')) # ToDo: NEEED CHECK IS A HARD DRIVE OR SOMETHING ELSE for pd_id in "${pd_list[@]}"; do @@ -130,9 +128,8 @@ LLDPhysicalDrives() { i=$((i+1)) done - - pd_json=$(echo $pd_json | sed -e 's/,$//') - lld_data="{\"data\":[$pd_json]}" + + lld_data="{\"data\":[${pd_json::-1}]}" echo $lld_data } @@ -161,10 +158,10 @@ GetControllerStatus() { ctrl_status="" case "$ctrl_part" in "main") - ctrl_status=$($cli GETCONFIG $ctrl_id AD | grep "Controller Status" | cut -f2 -d":" | sed -e 's/^ //' ) + ctrl_status=$($cli GETCONFIG $ctrl_id AD | grep "Controller Status" | cut -f2 -d":" | xargs ) ;; "battery") - ctrl_status=$($cli GETCONFIG $ctrl_id AD | grep -E "^\s+Status\s+[:]" | cut -f2 -d":" | sed -e 's/^ //' ) + ctrl_status=$($cli GETCONFIG $ctrl_id AD | grep -E "^\s+Status\s+[:]" | cut -f2 -d":" | xargs ) ;; "temperature") ctrl_status=$($cli GETCONFIG $ctrl_id AD | grep -E "^\s+Temperature\s+[:]" | cut -f2 -d":" | awk '{print $1}' ) @@ -178,7 +175,7 @@ GetLogicalDriveStatus() { ctrl_id=$1 ld_id=$2 - ld_status=$($cli GETCONFIG $ctrl_id LD $ld_id | grep "Status of logical device" | cut -f2 -d":" | sed -e 's/^ //' ) + ld_status=$($cli GETCONFIG $ctrl_id LD $ld_id | grep "Status of Logical Device" | cut -f2 -d":" | xargs ) echo $ld_status } @@ -195,28 +192,28 @@ GetPhysicalDriveStatus() { GetSmartHealth() { disk_dev=$1 - disk_health=$($cli_smart -H $disk_dev | grep "SMART Health Status" | cut -f2 -d":" | sed -e 's/^ //' ) + disk_health=$($cli_smart -H $disk_dev | grep "SMART Health Status" | cut -f2 -d":" | xargs ) echo $disk_health } GetSmartTemp() { disk_dev=$1 - disk_temp=$($cli_smart -A $disk_dev | grep "Current Drive Temperature" | cut -f2 -d":" | cut -f1 -d"C" | sed -e 's/^ //' ) + disk_temp=$($cli_smart -A $disk_dev | grep "Current Drive Temperature" | cut -f2 -d":" | cut -f1 -d"C" | xargs ) echo $disk_temp } GetSmartTripTemp() { disk_dev=$1 - disk_temp=$($cli_smart -A $disk_dev | grep "Drive Trip Temperature" | cut -f2 -d":" | cut -f1 -d"C" | sed -e 's/^ //' ) + disk_temp=$($cli_smart -A $disk_dev | grep "Drive Trip Temperature" | cut -f2 -d":" | cut -f1 -d"C" | xargs ) echo $disk_temp } GetSmartDefects() { disk_dev=$1 - disk_defects=$($cli_smart -A $disk_dev | grep "Elements in grown defect list" | cut -f2 -d":" | sed -e 's/^ //' ) + disk_defects=$($cli_smart -A $disk_dev | grep "Elements in grown defect list" | cut -f2 -d":" | xargs ) echo $disk_defects } @@ -272,4 +269,4 @@ case "$action" in *) echo "Invalid usage of script" ;; -esac \ No newline at end of file +esac