Advertisement
Guest User

Untitled

a guest
Feb 28th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.06 KB | None | 0 0
  1. arg1=$1
  2.  
  3. case $arg1 in
  4.  
  5.     "ready")
  6.         csvHeader="vCPU, %READY, status"
  7.         entityMatch="vmx-vcpu.*Ready"
  8.         maxPassValue="499"
  9.         # i.e. 4.99
  10.         ;;
  11.  
  12.     "vdiskread")
  13.         csvHeader="vDisk, Read (ms), status"
  14.         entityMatch="Virtual Disk.*scsi.*MilliSec/Read"
  15.         maxPassValue="499"
  16.         ;;
  17.        
  18.     "vdiskwrite")
  19.         csvHeader="vDisk, Write (ms), status"
  20.         entityMatch="Virtual Disk.*scsi.*MilliSec/Write"
  21.         maxPassValue="499"
  22.         ;;
  23.     *)
  24.         echo "no argument specified, use: ready, vdiskread, vdiskwrite"
  25.         exit
  26.  
  27. esac
  28.  
  29. esxtopDirectory="$(ls -F *.csv)"
  30. outputCsv="./output/output_${arg1}.csv"
  31.  
  32. if [ ! -f "${outputcsv}" ]
  33. then
  34.         echo "${csvHeader}" > "${outputCsv}"
  35. else
  36.         echo "${outputCsv} already exists"
  37. fi
  38.  
  39. for esxtopBatchFile in "${esxtopDirectory}"
  40. do
  41.     columnListCount=$(head -1 ${esxtopBatchFile} | tr ',' '\n' | nl | sed -e 's/^[[:space:]]*//' | sed -r 's/\s/,/' | grep -e "${entityMatch}" | wc -l)
  42.     if [ "$columnListCount" != "0" ]
  43.     then
  44.         columnList=$(head -1 ${esxtopBatchFile} | tr ',' '\n' | nl | sed -e 's/^[[:space:]]*//' | sed -r 's/\s+/,/' | grep -e "${entityMatch}")
  45.         columnNumber=$(echo -en "${columnList}" | awk -F "," '{print $1}')
  46.         printf "%+10s %+8s %+8s   %-36s\n" "Line#" "Value" "Status" "Name"
  47.         printf -- '-%.0s' $(seq 150); echo ""
  48.         while IFS= read -r line
  49.         do
  50.  
  51.             entityName=$(cat ${esxtopBatchFile} | awk -F "," -v var=$line 'BEGIN{ans=var} {print $ans}' | head -1 | cut -d "\\" -f 4)
  52.             result=$(cat ${esxtopBatchFile} | awk -F "," -v var=$line 'BEGIN{ans=var} {print $ans}' | tail -n +2 | tr -d '"'| sort -r | head -1)
  53.             resultInteger=$(echo "${result}" | tr -dc '0-9')
  54.  
  55.             #echo ${result}
  56.             #echo ${resultInteger}
  57.  
  58.             if [ "${resultInteger}" -ge "${maxPassValue}" ]
  59.             then
  60.                 status="FAIL"
  61.             else
  62.                 status="PASS"
  63.             fi
  64.            
  65.             echo "${entityName},${resultInteger},${status}" >> "${outputCsv}"
  66.            
  67.             printf "%+10s %+8s %+8s   %-36s\n" "${line}" "${result}" "${status}" "${entityName}"
  68.            
  69.         done <<<"${columnNumber}"
  70.     else
  71.         echo "skipping ${esxtopBatchFile}, \"${entityMatch}\" didn't match any columns"
  72.     fi
  73. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement