Code:
#|/bin/bash
# ----------------------------------------------- #
# storageconsumption.sh #
# Storage max / min values #
# Version 1.0 #
# by: #
# ----------------------------------------------- #
fileactual="fileactual.csv"
fileMaxMin="maxminconsumption.csv"
filemax="filemax.csv"
filemin="filemin.csv"
filecomparemax="comparemax.csv"
filecomparemin="comparemin.csv"
#--------print all the df data to the actualfile
df -hP | awk '{print $0}' > $fileactual
#-------Check if file exists, if it donst will save fresh data from DF command
if [ ! -f $filemax ]; then
df -hP | awk '{print $0}' > $filemax
fi
if [ ! -f $filemin ]; then
df -hP | awk '{print $0}' > $filemin
fi
#--------past the 2 files in a new one so in the next command "awk" we can compare the columms
paste -d" " $fileactual $filemax > $filecomparemax
paste -d" " $fileactual $filemin > $filecomparemin
#-------selecing the biger value on column 3 = used space and print the total row. colummns 1 to 6 is from the actual file, 7 to 12 is from the filemax / filemin
awk '$3 > $9 {print $1","$2","$3","$4","$5","$6}; $3 < $9 {print $7","$8","$9","$10","$11","$12} ; $3==$9 {print $7","$8","$9","$10","$11","$12}' $filecomparemax > $filemax
#-------selecing the lower value on column 3 = used space and print the row
awk '$3 < $9 {print $1","$2","$3","$4","$5","$6}; $3 > $9 {print $7","$8","$9","$10","$11","$12} ; $3==$9 {print $7","$8","$9","$10","$11","$12}' $filecomparemin > $filemin
#-------print the header of our final file.
echo 'THIS IS THE MAX VALUES
-----------------,-----------------,-----------------,-----------------,-----------------,----------------- ' > $fileMaxMin
#-------print our MAX values
cat $filemax >> $fileMaxMin
echo '-----------------,-----------------,-----------------,-----------------,-----------------,-----------------
THIS IS THE LOWER VALUES
-----------------,-----------------,-----------------,-----------------,-----------------,----------------- ' >> $fileMaxMin
#-------print our MIN values
cat $filemin >> $fileMaxMin
#------- delete desnecessary files.
rm $filecomparemax
rm $filecomparemin
rm $fileactual