Advertisement
Guest User

Untitled

a guest
Feb 28th, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.65 KB | None | 0 0
  1. esxitopdirectory="$(ls)"
  2. outputcsv="output_foo.csv"
  3.  
  4. if [ ! -f "output_foo.csv" ]
  5. then
  6.         echo "vcpuname, %ready result, status" > "${outputcsv}"
  7. else
  8.         echo "{outputcsv} already exists"
  9. fi
  10.  
  11. for FILE in "${esxitopdirectory}"
  12. do
  13.     collistcount=$(head -1 $FILE | tr ',' '\n' | nl | sed -e 's/^[[:space:]]*//' | sed -r 's/\s/,/' | grep "Ready" | grep "vcpu" | wc -l)
  14.     if [ "$collistcount" != "0" ]
  15.     then
  16.         collist=$(head -1 $FILE | tr ',' '\n' | nl | sed -e 's/^[[:space:]]*//' | sed -r 's/\s+/,/' | grep "Ready" | grep "vcpu")
  17.         colnumber=$(echo -en "$collist" | awk -F "," '{print $1}')
  18.         #echo "${collist}"
  19.         #echo "${colnumber}"
  20.         echo "==========================================="
  21.  
  22.         while IFS= read -r line
  23.         do
  24.             echo ""
  25.             line=$(( $line - 1 ))
  26.             # line -1, havent' checked why colnumber might be one off          
  27.             echo "Line: $line"
  28.             vcpuname=$(cat $FILE | awk -F "," -v var=$line 'BEGIN{ans=var} {print $ans}' | head -1)
  29.  
  30.             echo "${vcpuname}"
  31.             echo "==========================================="
  32.             readyresult=$(cat $FILE | awk -F "," -v var=$line 'BEGIN{ans=var} {print $ans}' | tail -n +2 | tr -d '"'| sort -r | head -1)
  33.             readyresultin=$(echo "${readyresult}" | tr -dc '0-9')
  34.  
  35.             #echo $readyresult
  36.             #echo $readyresultin
  37.  
  38.             if [ "${readyresultin}" -ge "499" ];then
  39.                     echo "$readyresult FAIL"
  40.                     echo "${vcpuname},${readyresult},FAIL" >> "${outputcsv}"
  41.                     else
  42.                     echo "${readyresult} PASS"
  43.                     echo "${vcpuname},${readyresult},PASS" >> "${outputcsv}"
  44.             fi
  45.             echo "==========================================="
  46.         done <<<"${colnumber}"
  47.     else
  48.         echo "skipping $FILE no virtual machines found"
  49.     fi
  50. done
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement