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 }
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.