Operating System - Linux
1753483 Members
4027 Online
108794 Solutions
New Discussion юеВ

Re: shell script for disk space in GB

 
SOLVED
Go to solution
Shivkumar
Super Advisor

shell script for disk space in GB

Dear Sirs,

I need a shell script to find total disk space available, used and and free in terms of GB.

Thanks,
Shiv
18 REPLIES 18
Steven E. Protter
Exalted Contributor

Re: shell script for disk space in GB

MB

#!/usr/bin/ksh

echo "Filesystem Mbytes used avail %used Mounted on"

bdf $1 | grep -v Filesystem | awk '{ printf("%s %10d %10d %10d %4s %s\n",$1,$2/
1024,$3/1024,$4/1024,$5,$6)}'


for GB

#!/usr/bin/ksh

echo "Filesystem Gbytes used avail %used Mounted on"

bdf $1 | grep -v Filesystem | awk '{ printf("%s %10d %10d %10d %4s %s\n",$1,$2/
1024,$3/1024,$4/1024/1024,$5,$6)}'


SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor
Solution

Re: shell script for disk space in GB

typo

#!/usr/bin/ksh

echo "Filesystem Gbytes used avail %used Mounted on"

bdf $1 | grep -v Filesystem | awk '{ printf("%s %10d %10d %10d %4s %s\n",$1,$2/
1024/1024,$3/1024,$4/1024/1024,$5,$6)}'
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: shell script for disk space in GB

Hi Shiv:

With all due respect, you would learn a great deal more by posting *what* you have tried to create and then asking for help where you are stuck.

Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: shell script for disk space in GB

Shiv,

I got this from Patrick Wallek (attached).


Pete

Pete
Orhan Biyiklioglu
Respected Contributor

Re: shell script for disk space in GB

You should also check the di tool available at Merjin's software archieve:

http://mirrors.develooper.com/hpux/downloads.html

di -d G

will give you filesystem information in GBs.


Filesystem Mount Gigs Used Avail %used fs Type

hth
Shivkumar
Super Advisor

Re: shell script for disk space in GB

Is it possible to print the summary of total available,used and free in GB ?
James R. Ferguson
Acclaimed Contributor

Re: shell script for disk space in GB

Hi Shiv:

#!/usr/bin/sh
bdf | awk '!/Filesystem/ {
s2+=$2;s3+=$3;s4+=$4;
printf("%-18s %10d %10d %10d %4s %s\n",
$1,$2/1024/1024,$3/1024/1024,$4/1024/1024,$5,$6)}
END{printf "%-18s %10d %10d %10d\n","TOTAL",
s2/1024/1024,s3/1024/1024,s4/1024/1024}'

...while not formatted to be pretty, I think this gives you want you want. Columns do not quite add up due to rounding.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: shell script for disk space in GB

Hi (again) Shiv:

I should have said (of course) that "Columns do not quite add up due to integer truncation."

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: shell script for disk space in GB

Hi Shiv:

This last hack does a better job of formatting the output and replaces the printf() integers with rounded reals (via "%10.2f"). You will find that the columnar totals are much closer to their expected values.

#!/usr/bin/sh
bdf | awk '
BEGIN{printf "%-16s %10s %10s %10s %5s %s\n",
"Filesystem","GB","Used","Avail","Used","Mounted_On"};
!/Filesystem/ {
s2+=$2;s3+=$3;s4+=$4;
printf("%-16s %10.2f %10.2f %10.2f %5s %s\n",
$1,$2/1024/1024,$3/1024/1024,$4/1024/1024,$5,$6)}
END{printf "%-16s %10.2f %10.2f %10.2f\n","TOTAL",
s2/1024/1024,s3/1024/1024,s4/1024/1024}'

Regards!

...JRF...