I need to make a bash script to compare the space of a vg on redhat servers. What I have so far is:
#!/bin/bash
##VARS
CMD=$(vgs | grep vgSoft | awk -F" " '{print $7}' | awk -F"<" '{print $2}'| awk -F"g" '{print $1}')
SPACE="10.00"
if [[ "$CMD" < "$SPACE" ]]; then
echo "It's not enough space, you must extend the VG"
echo "Space is equal to: $CMD GB"
elif [[ "$CMD" == "$SPACE" ]]; then
echo "It's enough space but consider extend the VG"
elif [[ "$CMD" > "$SPACE" ]]; then
echo "It's enough space"
echo "Space is equal to: $CMD GB"
fi
What do I do with this command is obtaing the output of volume groups and parse the data for obtain the desired value vgs | grep vgSoft | awk -F" " '{print $7}' | awk -F"<" '{print $2}'| awk -F"g" '{print $1}'
and save it to the CMD variable.
Where the output of vgs
command is:
[root@server~]# vgs
VG #PV #LV #SN Attr VSize VFree
vgSoft 2 13 0 wz--n- 71.99g <26.14g
vgSys 1 12 0 wz--n- <63.51g <36.52g
So in this case, the result of my CMD variable is 26.14 And I'm making the comparison with the value 10.00 (which is assigned to the SPACE variable).
But I'm having an issue comparing the strings, because is the output of vgs
command is for example 9.46 the script says me that "It's enough space" when the output should be "It's not enough space, you must extend the VG".
As far I remember I don't be able to use the operators "eq" "gt" "ne" because I'm comparing to strings and not integer values.