script required to check the size of Directory (2914 Views)
Reply
Trusted Contributor
mjoshi
Posts: 618
Registered: ‎01-06-2010
Message 1 of 20 (2,914 Views)
Accepted Solution

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
Acclaimed Contributor
Dennis Handly
Posts: 25,290
Registered: ‎03-06-2006
Message 2 of 20 (2,914 Views)

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
Trusted Contributor
mjoshi
Posts: 618
Registered: ‎01-06-2010
Message 3 of 20 (2,915 Views)

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
Esteemed Contributor
g3jza
Posts: 313
Registered: ‎01-30-2008
Message 4 of 20 (2,914 Views)

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
Acclaimed Contributor
Dennis Handly
Posts: 25,290
Registered: ‎03-06-2006
Message 5 of 20 (2,913 Views)

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/?
Trusted Contributor
mjoshi
Posts: 618
Registered: ‎01-06-2010
Message 6 of 20 (2,913 Views)

Re: script required to check the size of Directory

du -ks is working...

Acclaimed Contributor
Dennis Handly
Posts: 25,290
Registered: ‎03-06-2006
Message 7 of 20 (2,913 Views)

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.
Esteemed Contributor
g3jza
Posts: 313
Registered: ‎01-30-2008
Message 8 of 20 (2,913 Views)

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...
Trusted Contributor
mjoshi
Posts: 618
Registered: ‎01-06-2010
Message 9 of 20 (2,913 Views)

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

Esteemed Contributor
g3jza
Posts: 313
Registered: ‎01-30-2008
Message 10 of 20 (2,913 Views)

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 }'
Esteemed Contributor
g3jza
Posts: 313
Registered: ‎01-30-2008
Message 11 of 20 (2,885 Views)

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


Acclaimed Contributor
Dennis Handly
Posts: 25,290
Registered: ‎03-06-2006
Message 12 of 20 (2,885 Views)

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)}')
Trusted Contributor
mjoshi
Posts: 618
Registered: ‎01-06-2010
Message 13 of 20 (2,885 Views)

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

Acclaimed Contributor
Dennis Handly
Posts: 25,290
Registered: ‎03-06-2006
Message 14 of 20 (2,885 Views)

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)}'`
Trusted Contributor
mjoshi
Posts: 618
Registered: ‎01-06-2010
Message 15 of 20 (2,885 Views)

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
Trusted Contributor
mjoshi
Posts: 618
Registered: ‎01-06-2010
Message 16 of 20 (2,885 Views)

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
Esteemed Contributor
g3jza
Posts: 313
Registered: ‎01-30-2008
Message 17 of 20 (2,885 Views)

Re: script required to check the size of Directory

SUN :) .

this is hp-ux forum...
Esteemed Contributor
g3jza
Posts: 313
Registered: ‎01-30-2008
Message 18 of 20 (2,885 Views)

Re: script required to check the size of Directory

you should ask this question to some Oracle / Solaris forums....
Regular Advisor
Stephan_
Posts: 68
Registered: ‎07-07-2010
Message 19 of 20 (2,881 Views)

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 ..."
Honored Contributor
H.Merijn Brand (procura
Posts: 6,189
Registered: ‎10-13-1997
Message 20 of 20 (2,827 Views)

Re: script required to check the size of Directory

[ Edited ]

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
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.