Operating System - HP-UX
1777305 Members
3369 Online
109068 Solutions
New Discussion

Re: how can i get size of block device (perl, shell script)

 
SOLVED
Go to solution
support_billa
Valued Contributor

how can i get size of block device (perl, shell script)


i can't find any perl-func which shows the size of a block device ?
does a perl-func exist ?

Example: LVOL Size of /dev/vgfs/filesystem is 256 MB.

or other ways to parse one of the following commands in a SHELL ?

commands easy to parse are "/usr/sbin/fstyp -v" or "df -g" ?

# bdf /filesystem
Filesystem          kbytes    used   avail %used Mounted on
/dev/vgfs/filesystem
                   2097152   30912 2050104    1% /filesystem
# df -g /dev/vgfs/filesystem
/filesystem         (/dev/vgfs/filesystem) :
           8192 file system block size            8192 fragment size
         262144 total blocks                    258280 total free blocks
         256263 allocated free blocks            74816 total i-nodes
          64544 total free i-nodes               64544 allocated free i-nodes
     1073807412 file system id                    vxfs file system type
           0x11 flags                             255 file system name length
 /filesystem file system specific string

# df -i /dev/vgfs/filesystem
/filesystem         (/dev/vgfs/filesystem) :    74816 total i-nodes
                                                     64544 free i-nodes
                                                     10272 used i-nodes
                                                        13 % i-nodes used
# df -P /dev/vgfs/filesystem
Filesystem             512-blocks  Used  Available Capacity Mounted on
/dev/vgfs/filesystem 4162032    61824  4100208     2%     /filesystem

# /usr/sbin/fstyp -v /dev/vgatvmv3tfs/io_src_test_s
vxfs
version: 7
f_bsize: 8192
f_frsize: 8192
f_blocks: 262144

how can i dectect, if LVOL SIZE differs from BLOCK SIZE ?
- lvdisplay
- fstyp -v
- compare the results ?

regards

16 REPLIES 16
James R. Ferguson
Acclaimed Contributor

Re: how can i get size of block device (perl, shell script)


@support_billa wrote:


i can't find any perl-func which shows the size of a block device ?
does a perl-func exist ?

<snip>


# /usr/sbin/fstyp -v /dev/vgatvmv3tfs/io_src_test_s
vxfs
version: 7
f_bsize: 8192
f_frsize: 8192
f_blocks: 262144

how can i dectect, if LVOL SIZE differs from BLOCK SIZE ?
- lvdisplay
- fstyp -v
- compare the results ?


It appears that you are interested in comparing the VxFS preferred system block size ('bsize') versus the fundamental block size ('frsize').

 

I can think of two options: (1) query and compare the results in a script, yourself; or (2) use the Perl 'Filesys::Statvfs' module from CPAN which leverages the underlying system call 'statvfs(2)'.

 

See the 'statvfs(2)' manpages for more information, too.

 

Regards!

 

...JRF...

 

support_billa
Valued Contributor

Re: how can i get size of block device (perl, shell script)


i want to get the size of a block_device , maybe in KB
i found in this forum now , that "bdf" and "df" differs , right ?

LVOL SIZE of /dev/vgfs/filesystem is maybe 512 MB but
the TOTAL BLOCK SIZE is 256 MB (anybody forget to extend filesystem ).

so i found to find out , what is the size of the block device.


in the example:

bdf shows output over 2 lines :

# bdf /filesystem
Filesystem          kbytes    used   avail %used Mounted on
/dev/vgfs/filesystem
                   2097152   30912 2050104    1% /filesystem

# df -g /dev/vgfs/filesystem
         262144 total blocks                    258280 total free blocks

then i compare "TOTAL BLOCK SIZE" and "LV_SIZE" ?

- but how can i get the "TOTAL BLOCK SIZE" ?
- also how can i get free usage in percent ?

regards

 

support_billa
Valued Contributor

Re: how can i get size of block device (perl, shell script)

hello,

 

what i am now detect, when "fragment size" and "file system block size " are equal, "bdf" and "df" differs :

 

here "bdf" and "df" differs :

 

df -g /filesystem
/filesystem         (/dev/vgfilesystem/filesystem) :
           8192 file system block size            8192 fragment size
         262144 total blocks                    258280 total free blocks
         256263 allocated free blocks            74816 total i-nodes
          64544 total free i-nodes               64544 allocated free i-nodes
     1073807412 file system id                    vxfs file system type
           0x11 flags                             255 file system name length
 /filesystem file system specific string

bdf /filesystem
Filesystem          kbytes    used   avail %used Mounted on
/dev/vgfilesystem/filesystem
                   2097152   30912 2050104    1% /filesystem

 

 

here "bdf" and "df" is ok :

 

df -g /dev/vgfilesystem/filesystem_ok
/filesystem_ok               (/dev/vgfilesystem/filesystem_ok) :
           8192 file system block size            1024 fragment size
         524288 total blocks                    287654 total free blocks
         269777 allocated free blocks            75892 total i-nodes
          71912 total free i-nodes               71912 allocated free i-nodes
     1073807364 file system id                    vxfs file system type
           0x10 flags                             255 file system name length
       /filesystem_ok file system specific string

bdf /dev/vgfilesystem/filesystem_ok
Filesystem          kbytes    used   avail %used Mounted on
/dev/vgfilesystem/filesystem_ok
                    524288  236634  269676   47% /filesystem_ok

James R. Ferguson
Acclaimed Contributor

Re: how can i get size of block device (perl, shell script)


@support_billa wrote:


- but how can i get the "TOTAL BLOCK SIZE" ?
- also how can i get free usage in percent ?


Hi:

 

You can use the output of 'bdf to get the total block size in kbytes.  You can also use 'df -k' to see the KB allocated and the percentage used.  The free usage percentage is ( 100 - percent_used ).

 

Regards!

 

...JRF...

James R. Ferguson
Acclaimed Contributor
Solution

Re: how can i get size of block device (perl, shell script)


@support_billa wrote:

what i am now detect, when "fragment size" and "file system block size " are equal, "bdf" and "df" differs

 


No, you are misreading this.

 

For your filesystem with 8192 for the fragment size:

 

262144*8192/1024 = 2097192

 

....which is exactly what 'bdf' reports.

 

For your filesystem with a 1024 fragment size:

 

there are 524,288 total blocks shown which is exactly what 'bdf' reports.

 

1024 = 1KB, or the units used by 'bdf'

 

Regards!

 

...JRF...

H.Merijn Brand (procura
Honored Contributor

Re: how can i get size of block device (perl, shell script)

There are perl modules to do that, but they may be too old to do it very accurate:

• Filesys::Df ( https://metacpan.org/module/Filesys::Df )

• Filesys::DiskFree ( https://metacpan.org/module/Filesys::DiskFree )

• HPUX::FS ( https://metacpan.org/module/HPUX::FS )

• HPUX::LVM ( https://metacpan.org/module/HPUX::LVM )

but they might be too old to be accurate enough. YMMV 

Enjoy, Have FUN! H.Merijn
support_billa
Valued Contributor

Re: how can i get size of block device (perl, shell script)

about :


For your filesystem with 8192 for the fragment size:

 262144*8192/1024 = 2097192

 ...which is exactly what 'bdf' reports.

 

For your filesystem with a 1024 fragment size:

 

there are 524,288 total blocks shown which is exactly what 'bdf' reports.

 

1024 = 1KB, or the units used by 'bdf'


for my understanding :

when "fragment size" and "file system block size " are equal :

i have to use :  262144*8192/1024 = 2097192   ( 1024 = 1KB )

 

when "fragment size" and "file system block size "differs :

the "file system block size " is the exact value !

 

regards

 

support_billa
Valued Contributor

Re: how can i get size of block device (perl, shell script)

more questions :

1. best way to parse "bdf", when it reports is over 2 lines :

2. questions to "df" and "bdf"

 

1. best way to parse "bdf", when it reports is over 2 lines :

example of "bdf"

Filesystem          kbytes    used   avail %used Mounted on
/dev/vgfilesystem/filesystem_ok
                    524288  236634  269777   47% /filesystem_ok
/dev/vg00/lvol6    2097152  835448 1253024   40% /tmp

 

AWK, when it reports is over 2 lines:


local_fs=/tmp

bdf ${local_fs} | awk -v FSYS="${local_fs}" '
NF>=6 && $6 ~ FSYS { printf "%-26s %10s %10s %10s %5s %s\n",$1,$2,$3,$4,$5,$6 }
NF==1 { l=$1 }
NF==5 && $5 ~ FSYS { printf "%-26s %10s %10s %10s %5s %s\n",l,$1,$2,$3,$4,$5 }'

 


2. questions to "df" and "bdf"

 

i have a large fs and "df" reports 100 % usage , "bdf" 99 % usage :

 

Filesystem          kbytes    used   avail %used Mounted on
/dev/vgfsdepot/lvol1
                    227540992 225622902 1802529   99% /filesystem_large

 

questions to the output below:

 

df -P should show the size of the file system, but it is not the value of "bdf", must i know the block_size ?

only df -g reports the same value of "bdf".

 

what is the best way to parse informations of filesystem ? "bdf" or "df" or to install the perl modules ?

 

for my issue , i need 2 functions like "get_size_of_fs" and "get_percent_of_fs_usage"

 

man of "df -P"

-P   Report the name of the file system, the size of
     the file system, the number of blocks used, the
     number of blocks free, the percentage of blocks
     used and the directory below which the file system
     hierarchy appears.

# df -P /filesystem_large
Filesystem             512-blocks  Used  Available Capacity Mounted on
/dev/vgfsdepot/lvol1 454850862 451245804  3605058   100%     /filesystem_large
# df -Pk /filesystem_large
Filesystem            1024-blocks  Used  Available Capacity Mounted on
/dev/vgfsdepot/lvol1 227425431 225622902  1802529   100%     /filesystem_large

man of "df -g"
-g    Report the entire structure described in statvfs(2).

 df -g /filesystem_large
 /filesystem_large            (/dev/vgfsdepot/lvol1) :
    8192    file system block size            1024 fragment size
  227540992 total blocks                   1918090 total free blocks
  1802529   allocated free blocks          2495396 total i-nodes
   479522   total free i-nodes              479522 allocated free i-nodes
1074069505  file system id                    vxfs file system type
   0x10 flags                             255 file system name length
 /filesystem_large file system specific string

support_billa
Valued Contributor

Re: how can i get size of block device (perl, shell script)

Hello H.Merijn ,

i installed for tests all your listed perl modules :

@ Filesys::Df ( https://metacpan.org/module/Filesys::Df )
works perfect

@ Filesys::DiskFree ( https://metacpan.org/module/Filesys::DiskFree )
works ok, but shows a lot of warnings !

@ HPUX::FS ( https://metacpan.org/module/HPUX::FS )
@ HPUX::LVM ( https://metacpan.org/module/HPUX::LVM )

HPUX::LVM doesn't work , because show error of "vgdisplay -v" ...

so Filesys::Df is ok and i find about to install it !

regards

James R. Ferguson
Acclaimed Contributor

Re: how can i get size of block device (perl, shell script)


@support_billa wrote:

more questions :

1. best way to parse "bdf", when it reports is over 2 lines :


You seem to have solved this.  Bill Hassell has a very nice script that handles 2-line 'bdf' output and adds lots of useful information in addition to improving the output formatting.  See this thread for a copy:

 

http://h30499.www3.hp.com/t5/System-Administration/bdfmegs-version-5-8-available/m-p/4673433/highlight/true#M381988

 


@support_billa wrote:

more questions :

 

2. questions to "df" and "bdf"

 

i have a large fs and "df" reports 100 % usage , "bdf" 99 % usage :


Different tools often use different methods to deduce things.  You are quibbling over small differences.  What exactly is the problem you are attempting to solve?  It seems that this is becoming an academic exercise rather than one to solve a real-world problem.

 

That said, look at the 'df' and 'bdf' manpages.  From 'df(1M)', "The df command displays the number of free 512-byte blocks and free inodes available for file systems by examining the counts kept in the superblock or superblocks."   In contrast, from 'bdf(1M)', "Non-HFS file systems may have other items not accounted for by this command."

 

Regards!

 

...JRF...

support_billa
Valued Contributor

Re: how can i get size of block device (perl, shell script)


@Bill Hassell has a very nice script that handles 2-line 'bdf' output 
@_________________________________________________________________________________________________________
@ http://h30499.www3.hp.com/t5/System-Administration/bdfmegs-version-5-8-available/m-p/4673433/highlig...

thank you

i have a large fs and "df" reports 100 % usage , "bdf" 99 % usage :

sorry, maybe i am quibbling over small differences.
i was looking about a command to save easy in a shell variable the value of the block device size .
i thought , this would be a short task , i know "bdf" and "df" and i hope that a perl function will exist ...
perl module exists, but not in a core module , so i read "bdf" and "df" man pages and then i detected those
difference above :-( i asked also my colleagues , they had also no  explanation.

From 'df(1M)' : there are a lot of options, which i didn't know it before and i read it exactly and only "df -g"
shows exact the same value (without multiply , divide ..) like "bdf"

you explain the difference very good , so i understand it know.

finaly , i also don't like to write a degree dissertation about those commands !
so i will stop it now and thanks to your great response

VK2COT
Honored Contributor

Re: how can i get size of block device (perl, shell script)

Hello,

 

Why reinvent the wheel when you can use simle tools native to HP-UX:

 

# /opt/ignite/bin/print_manifest

...

File System layout

    LVM Device file            mount point     size  fs type
    /dev/vg00:
    /dev/vg00/lvol1            /stand          1792  vxfs
    /dev/vg00/lvol2            swap            4096
    /dev/vg00/lvol3            /               95584 vxfs
    /dev/vg00                  unallocated     0
    /dev/vg01:
    /dev/vg01/lvol10           /guests1        149984vxfs
    /dev/vg01                  unallocated     3584

Or,

 

# /usr/sam/lbin/lvlist -p
/dev/vg00/lvol1|/dev/vg00|vxfs|1792|0|LVM|/stand|266240|available/syncd|1
/dev/vg00/lvol2|/dev/vg00|swap/dump|4096|0|LVM|-|131330|available/syncd|1
/dev/vg00/lvol3|/dev/vg00|vxfs|95584|0|LVM|/|266240|available/syncd|1
/dev/vg01/lvol10|/dev/vg01|vxfs|149984|0|LVM|/guests1|266240|available/syncd|1

Or,

 

# /usr/sam/lbin/vginfo -v
vg00:available,read/write@:255:16:3:1:0:32:3737:101472:0:0:3171:0:0:/dev/vg00/lvol1@available/syncd@1792@56@1,/dev/vg00/lvol2@available/syncd@4096@128@1,/dev/vg00/lvol3@available/syncd@95584@2987@1:/dev/disk/disk12_p2@@available@3171@0::LVM
vg01:available,read/write@:16:16:1:1:0:32:4799:153568:3584:112:4799:0:0:/dev/vg01/lvol10@available/syncd@149984@4687@1:/dev/disk/disk31@@available@4799@112::LVM
slvm_dsk1:available,shared,client,read/write@brk13,brk11:2047:2048:0:1:0:4:51200:204788:204788:51197:51197:0:0::/dev/disk/disk13@@available@51197@51197::LVM

All these commands can pe parsed and proper information extracted easily.

 

VK2COT

VK2COT - Dusan Baljevic
H.Merijn Brand (procura
Honored Contributor

Re: how can i get size of block device (perl, shell script)

I'm in the middle of a discussion with the author of the "Disk Info" utility di which is also available for HP-UX..

This utility works on HP-UX as well as on all other Unix-like OS's and gives the output the same on allOS's.

 

I've talked him into implementing a new -c option to generate the output as csv, so it is extremely easy to parse.

If you are interested, keep your eyes open on  http://www.gentoo.com/di/

Enjoy, Have FUN! H.Merijn
support_billa
Valued Contributor

Re: how can i get size of block device (perl, shell script)

hello VK2COT,

 

@ Why reinvent the wheel when you can use simle tools native to HP-UX

@ All these commands can pe parsed and proper information extracted easily.

 

i have been working with HP-UX for many years and i have never heard about those commands !!!!

These are great commands and easy to parse !

 

Does a white paper exists about those commands ? I didn't find man pages !

 

i use for example  :

/usr/sam/lbin/fslist -p /tmp

 

and i can interprete many columns , but when i have informations what column include what value it is easier !

 

regards

 


VK2COT
Honored Contributor

Re: how can i get size of block device (perl, shell script)

Hello,

 

It is my pleasure to share information.

 

Yes, I know that these commands are not known to majority of users :)

 

I am a Senior Instructor in HP Education and IT Architect in Australia/New Zealand

(teaching all sorts of HP-UX, Solaris, LInux (Red Hat, SUSE and Ubuntu), 3PAR,

ServiceGuard, Data Protector, EVA and Ibris X9000 NAS courses. I am also

a Wordwide Unix Ambassador and Unix Profession Leadership team at HP

so it is lot of fun for me to work on unsual things.

 

Unfortunately, there are no manuals on these rare commands that I listed yesterday..

Some of the commands in ./usr/sam/lbin and Shell scripts and the only way to

learn what they do is to look into them.

 

Let me show some other intresting commands in this directory:

 

# paginglist

/dev/vg00/lvol2|dev|4194304|4.0 GB|0|0.0 KB|4194304|4.0 GB|0%|0|-|1|no|now|
reserve|reserve|0|0.0 KB|3667436|3.5 GB|-3667436|-3667436`KB||0||0|no|now|
total|total|4194304|4.0 GB|3667436|3.5 GB|526868|514.5 MB|87%|0|0|0|no|now|

# importablevgs
1:/dev/disk/disk11_p2

 

And then new way to check ServiceGuard:

 

# /opt/OV/bin/ovclusterinfo -a

 

This command supports other types of clusters:

 

           - Microsoft Clustering Services (Windows)

           - MC/ServiceGuard (HP-UX)

           - VERITAS Cluster Server (Solaris)

           - Sun Cluster (Solaris)

           - TRU64 Cluster (TCR)

           - Red Hat Advanced Server (RHAS)

           - HACMP (AIX)

           - Unknown.

If you want to learn more of the "unusual" commands take a look at my

Operations Acceptance Testing Perl script for HP-UX:

 

http://www.circlingcycle.com.au/Unix-sources/

 

Cheers,

 

VK2COT

VK2COT - Dusan Baljevic
H.Merijn Brand (procura
Honored Contributor

Re: how can i get size of block device (perl, shell script)

After maybe 40 mails with the author of di, I am glad to say that the just release new version 4.29 works on all HP-UX that I could access, ranging from 10.20 +DAportable to 11.31 with gcc/64
I have uploaded the depots to my site which should be in sync within 20 hours, so feel free to grab your copy. Some examples:

$ di -l -c
s,m,b,u,v,p,T
/dev/vg00/root,/,"400.0M","333.2M","66.3M",83%,vxfs
/dev/vg00/data,/data,"12.0G","11.3G","0.6G",95%,vxfs
/dev/vg00/home,/home,"512.0M","265.1M","246.9M",52%,vxfs
/dev/vg00/opt,/opt,"6.5G","6.1G","0.4G",95%,vxfs
/dev/vg00/pro,/pro,"24.0G","22.2G","1.8G",93%,vxfs
/dev/vg00/stand,/stand,"304.0M","183.2M","119.9M",61%,vxfs
/dev/vg00/tmp,/tmp,"2.0G","0.8G","1.2G",40%,vxfs
/dev/vg00/usr,/usr,"5.3G","2.2G","3.1G",42%,vxfs
/dev/vg00/var,/var,"4.5G","1.8G","2.7G",41%,vxfs
/dev/vg00/wrk,/wrk,"1.0G","0.3G","0.6G",37%,vxfs
$ di -c >di.csv
$ env DBI_DSN="dbi:CSV:f_ext=.csv/r" qs -L f di w p '>' 90
SCHEMA: merijn, TABLE: di
[.]
select    s, m, b, u, v, p, t
from      di
where     p > '90'
s             |m      |b    |u    |v   |p  |t
/dev/vg00/data|/data  |12.0G|11.3G|0.6G|95%|vxfs
/dev/vg00/opt |/opt   |6.5G |6.1G |0.4G|95%|vxfs
/dev/vg00/pro |/pro   |24.0G|22.2G|1.8G|93%|vxfs
$

qs is a perl script that acts as a command-line SQL query interpreter (qs = quick select), and used here just to demonstrate how easy the output of the new -c option for di is parsable (as a database). 

Enjoy, Have FUN! H.Merijn