Operating System - HP-UX
1777284 Members
2346 Online
109066 Solutions
New Discussion юеВ

script required to check the size of Directory

 
SOLVED
Go to solution
mjoshi
Trusted Contributor

script required to check the size of Directory

Required a script which will show the status for my : /exaccess/AM1/access/oblix/logs directory.

Once the size gets exceed to 60 GB

i.e if size for this exceeds to 60 GB then it shows the size else not.


With regards,
Mjoshi
19 REPLIES 19
Dennis Handly
Acclaimed Contributor

Re: script required to check the size of Directory

The following will give the size in 1Kb blocks:
du -kx /exaccess/AM1/access/oblix/logs
mjoshi
Trusted Contributor

Re: script required to check the size of Directory

Thanks Dennis, But i need in GB itself.

Though the cmd is failing :
du: illegal option -- x
usage: du [-a] [-d] [-h|-k] [-r] [-o|-s] [-H|-L] [file ...]

du -kx /exaccess/AM1/access/oblix/logs

Plz verify the cmd once again
g3jza
Esteemed Contributor
Solution

Re: script required to check the size of Directory

Hi,
du does not have the option to give the output in MB/GB. So you need to calculate it... or make an alias for the 'du' command.

to report size in KBytes:
du -ks /your/path
Dennis Handly
Acclaimed Contributor

Re: script required to check the size of Directory

>I need in GB itself.

Once you get the value in Kb, you can divide by 1 Mb to get Gb.

>Though the cmd is failing: du: illegal option -- x

du -x is perfectly valid under HP-UX. Or are you using a foreign devil du under /usr/local/bin/?
mjoshi
Trusted Contributor

Re: script required to check the size of Directory

du -ks is working...

Dennis Handly
Acclaimed Contributor

Re: script required to check the size of Directory

>du -ks is working.

-x is only needed if you wanted to make sure you didn't cross any mount points. In your case probably not likely so deep in your directory hierarchy.
g3jza
Esteemed Contributor

Re: script required to check the size of Directory

Dennis: Hmm, I didn't even know about the '-x' option, it can be quite useful...
mjoshi
Trusted Contributor

Re: script required to check the size of Directory

If i use for my scripting then is this script correct:

#!/bin/sh
cnt=0
cnt=`du -ks /tmp`
if [ $cnt -gt 1000 ]
then
opcmsg a=BAC o=EDMConnection msg_text="EDM Established Connection is $cnt" msg_grp=OpC s=major
fi



as i am facing an error while running it :

root@ggnems21 # sh logsize.sh
logsize.sh: test: unknown operator /tmp

g3jza
Esteemed Contributor

Re: script required to check the size of Directory

Well,
you need to pipe the du with some text editing tool, as du -ks /tmp also shows the '/tmp'. So something like this, if you want only number of kbytes from the du -ks output:

du -ks /tmp | awk '{ print $1 }'
g3jza
Esteemed Contributor

Re: script required to check the size of Directory

so the final script:

#!/bin/sh
cnt=0
cnt=`du -ks /tmp | awk '{ print $1 }'`
if [ $cnt -gt 1000 ]
then
opcmsg a=BAC o=EDMConnection msg_text="EDM Established Connection is $cnt" msg_grp=OpC s=major
fi


Dennis Handly
Acclaimed Contributor

Re: script required to check the size of Directory

>test: unknown operator /tmp

You need to separate out the size from the path:
cnt=$(du -ks /tmp | awk '{print $2}')

(Assuming that the size is the second field.)
If you want Gb you can do the divide in awk:
cnt=$(du -ks /tmp | awk '{printf "%d", $2/(1024*1024)}')
mjoshi
Trusted Contributor

Re: script required to check the size of Directory

@Dennis:

cnt=$(du -ks /tmp | awk '{printf "%d", $2/(1024*1024)}')

#!/bin/sh
cnt=0
cnt=$(du -ks /tmp | awk '{printf "%d", $2/(1024*1024)}')
if [ $cnt -gt 1000 ]
then
opcmsg a=BAC o=EDMConnection msg_text="The log level size exceeds 60 GB is $cnt" msg_grp=OpC s=major
fi


Output:
root@ggnems21 # sh EDMLogSize.sh
EDMLogSize.sh: syntax error at line 3: `cnt=$' unexpected

Dennis Handly
Acclaimed Contributor

Re: script required to check the size of Directory

>EDMLogSize.sh: syntax error at line 3: `cnt=$' unexpected

Again, this is perfectly valid syntax for a real shell. What OS are you running?
You can replace $() by the archaic `` construct:
cnt=`du -ks /tmp | awk '{printf "%d", $2/(1024*1024)}'`
mjoshi
Trusted Contributor

Re: script required to check the size of Directory

root@ggnems21 # uname -a
SunOS ggnems21 5.10 Generic_142900-02 sun4v sparc SUNW,SPARC-Enterprise-T5120
mjoshi
Trusted Contributor

Re: script required to check the size of Directory

Dennis its not runnning..


#!/bin/sh
cnt=0
cnt=`du -ks /tmp | awk '{printf "%d", $2/(1024*1024)}'`
if [ $cnt -gt 1000 ]
then
opcmsg a=BAC o=EDMConnection msg_text="The log level size exceeds 60 GB is $cnt" msg_grp=OpC s=major
fi
g3jza
Esteemed Contributor

Re: script required to check the size of Directory

SUN :) .

this is hp-ux forum...
g3jza
Esteemed Contributor

Re: script required to check the size of Directory

you should ask this question to some Oracle / Solaris forums....
Stephan_
Regular Advisor

Re: script required to check the size of Directory

Use ksh instead of sh in your first line, this will fix it on solaris.

 

hth,

Stephan

 

How to assign points on this new forums --> Kudos - what, where, how, and why!
How to find the right forum --> New forum location by ITRC tree

"we wouldn't call it code, if we could read it ..."
H.Merijn Brand (procura
Honored Contributor

Re: script required to check the size of Directory

I know that 'du' isn't 'di', but I'd like to share this related tool ...

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.

Enjoy, Have FUN! H.Merijn