Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to
calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting doesnt come easy for me.

So this is what Im trying to write specifically:

  • Calculate the sum of total space, used space for all matching filesystems
  • Display "Total Space = xx " ; "Used Space = yy"; "Free space = zz"
find / -name virginia 2>/dev/null
read ans_2
bdf * [ ans_2 ]
awk '{ s += $1 } END { print "Total Space: ", s, " Used Space: ", s/NR, " Free Space: ", NR }

Thanks in advance for any help!
BigBen

I don't get why you ask since you only accept 'oracle' and nothing else. It is not needed. I am assuming that there are directories in your file system(s) named 'oracle'
If the match is really '*oracle*' then change this code to match:

find / -name 'oracle' -type d |
while read fname
do
  bdf $fname 
done | awk '{ s += $1 } END { print "Total Space: ", s, " Used Space: ", s/NR, " Free Space: ", NR } '

I don't know what NR is supposed to do. NR is the number of records. It has nothing to do with free space or used space either. Used space is produced by bdf. Free space is total - used. s/NR divides the free space by the number of directories or filesystems.

If you just want to use "oracle" you wouldn't need a script like this...

$ cat ./bin/df.bash
#!/bin/bash

echo Please type Filesystem Name:

read fs

rs=`df -h | awk -v fs=$fs 'BEGIN {OFS="\n"} $1 ~ fs {print "Results for: " $1, "Total Size: " $2, "Used Space: " $3, "Free Space: " $4}'`

echo "${rs}"

Looks like Im way off....thanks for the help!

NR was supposed to read like the totals.

bigben

NR is an awk internal variable == number of lines processed for all input files
FNR == number of lines processed for current file

cat file | awk ........ means stdin is the file, so NR == FNR