Operating System - Linux
1828576 Members
2357 Online
109982 Solutions
New Discussion

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...
Muthukumar_5
Honored Contributor

Re: shell script for disk space in GB

Use this:

# bdf | awk 'BEGIN{ print "Filesystem GBytes Used avail %used Mounted on"}{ if ($0 ~! /Filesystem/) { printf "%s %6.5f %6.5f %6.5f %3s %s\n",$1,$2/1024/1024,$3/1024/1024,$4/1024/1024,$5,$6;}}'

hth.
Easy to suggest when don't know about the problem!
Shivkumar
Super Advisor

Re: shell script for disk space in GB

Thanks everyone for helping me!!

I have checked that both disks are available on the servers. Attached disks and SAN disk.

How to find out how much SAN disk is used, free ?

I mean i want separation of usage of SAN and attached disks both ?

Thanks,
Shiv

Onyedika Onwudiwe
Occasional Advisor

Re: shell script for disk space in GB

Shivkumar,

Depends on what you are looking for and from what perspective. Disk space available per LV, per VG. You might also have disks available on your system that have not been pvcreated but are available. Can you be more specific?
Shivkumar
Super Advisor

Re: shell script for disk space in GB

How to find out disks/disk space available on the systems that have not been pvcreated but are available ?
James R. Ferguson
Acclaimed Contributor

Re: shell script for disk space in GB

Hi SHiv:

# diskinfo /dev/rdsk/cXtYdZ

...will return the size of a disk. Note the use of the raw (character) device -- 'rdsk'.

See the manpages for more information, too.

Regards!

...JRF...
Arunvijai_4
Honored Contributor

Re: shell script for disk space in GB

Hi Shiv,

You can use the attached script finding out un-used disks,

Note : It works when you have Solution Enabler installed on your server.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Shivkumar
Super Advisor

Re: shell script for disk space in GB

What is solution enabler ? how to find out whether Solution Enabler is availaber on my servers ?
Bill Hassell
Honored Contributor

Re: shell script for disk space in GB

The syminq program is part of the EMC disk utilities package for newer disk arrays. Since EMC disk arrays are very expensive, you would definitely know if you have this package of tools.

As far as locating disks on your system which are not used, that is, not part of any disk volume group, you can run SAM and in the disks section, start creating a new volume group. The first step in SAM will show you potential disks you can use for a new volume or to extend an existing volume.


Bill Hassell, sysadmin
Onur Karakan
Advisor

Re: shell script for disk space in GB

Here is the script for disk space in 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/1024,$3/1024/1024,$4/1024/1024,$5,$6)}'


And you can find the script for used and available space for disks as ana attachment. It gives you detailed information about PVs,VGs and LVs. you only have to add your mail address to script.