Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A script that telle me when a file(s) get to 1.7GB or more 3

Status
Not open for further replies.

jpor

Technical User
Nov 29, 2000
212
GB
Hi Guys,

We currently run a database that unfortunately has a 2GB file size limit. It has caught me out a couple of times when files reach this limit and the database system becomes un-responsive. Does anybody have a script that monitors files so if they get to a particular size you can get a warning message?

Thnaks in advance.




( "To become Wise, first you must ask Questions")
 
In the man find page pay attention to the -size primary.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I assume you know the filename to be observed.
If you can live with delays in the range of seconds:
Code:
#!/bin/bash
#
#
observed=$1	# replace with your file
critical=3	# for testing set to 3 (kb)
#
while (true)
do
	# size in kb
	size=$(du $observed | sed 's/[ \t].*//g')
	if [[ $size -gt $critical ]] ; then
		# mail, ring bell, sendfax, shutdown - ...
		echo "size > $critical"
	fi
	sleep 10
done
Often database create big temporary files when answering queries, so when the problem occures suddenly, it might be too late.

seeking a job as java-programmer in Berlin:
 
Thanks Stefanwagner. Unfortunately I am attempting to run your script on AIX version 4.3.3 on KSH. And keep getting errors. Do you have a ksh version of your script?


( "To become Wise, first you must ask Questions")
 
No. I don't use ksh.
Can you tell where the error is?
Do you have sed on AIX?

On bash, the result of a command was made the content of a variable with backticks like this in former times:
Code:
size=`du $observed | sed 's/[ \t].*//g'`
which is now deprecated - but perhaps valid for ksh?

Do you have du (diskusage)?

seeking a job as java-programmer in Berlin:
 
I think that legacy sed don't transpose \t to tab.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Stefanwagner. This is the script you gave me with the file I am looking at:
#!/bin/ksh
#
#
observed=/usr/cs3/sysmprc/opdetm.dat # replace with your file
critical=3 # for testing set to 3 (kb)
#
while true
do
# size in kb
size=$(ls $observed | sed 's/[ \t].*//g')
if [[ $size -gt $critical ]] ; then
# mail, ring bell, sendfax, shutdown - ...
echo size > $critical
fi
sleep 10
done

This is the erro message I get:

chkfile.sc[10]: /usr/cs3/sysmprc/opde: 0403-057 Syntax error

Thanks.

( "To become Wise, first you must ask Questions")
 
I'm not sure that ksh supports the $(command) syntax. Try
Code:
#!/bin/ksh
#
#
observed=/usr/cs3/sysmprc/opdetm.dat    # replace with your file
critical=3    # for testing set to 3 (kb)
#
while true
do
    # size in kb
    size=`ls $observed | sed 's/[ \t].*//g'`
    if [[ $size -gt $critical ]] ; then
        # mail, ring bell, sendfax, shutdown - ...
        echo size > $critical
    fi
    sleep 10
done

Columb Healy
Living with a seeker after the truth is infinitely preferable to living with one who thinks they've found it.
 
Instead of
Code:
sed 's/[ \t].*//g'
you may write a file observe.sed:
Code:
s/[ \t].*//g
but instead of \t you put a normal tab into the file, and then call it:
Code:
sed -f observe.sed
Or perhaps you don't need the tab at all.

I don't known how 'ls' works under aix
With linux, you need to add the '-l' -option, to get filesizes.
But it gives a lot of unused information too.

So I can use
Code:
ls -l | colrm 1 31 | colrm 13
, but it's not elegant, and I'm not sure how it works for very big files.

Perhaps you can test every command on it's own?
You falsificated the existance of 'du'?

seeking a job as java-programmer in Berlin:
 
To get a file's size using ksh, just use...
Code:
size=$(ls -l file1|awk '{print $5}')

PS stefan, colrm was one of those BSD utilities that didn't really catch-on and is not available on many flavors of unix. It didn't catch-on because cut has the same functionality.
 
Yes - I tried cut, but I allways fail.
Need to buy a cut-Book I guess. :)

Ah - tried again, read man, and found out.
The problem is, that cut uses a single blank as delimiter, and 39 blanks in sequence as 39 delimiters.

So I have to compress multiple blanks to one:

Code:
size=$(ls -l file | sed 's/  */ /g' | cut -d ' ' -f 5)
The awk-code is smaller and uses only one program (sed + cut = 2) - but I don't know awk very good, and try to avoid it.

seeking a job as java-programmer in Berlin:
 
Thanks guys. ygor that works fine. Thanks

( "To become Wise, first you must ask Questions")
 
Another way: in ksh, without using the fearsome awk...
Code:
size=$(set -- $(ls -l file1); echo $5)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top