1833901 Members
1955 Online
110063 Solutions
New Discussion

Re: file size alert

 
SOLVED
Go to solution
Michael Campbell
Trusted Contributor

file size alert

Hi,
Does anybody know of a script which will send me an email when a file reaches a certain size. we need to know when a dump file nears 2GB.

Any ideas ?
6 REPLIES 6
Andreas Voss
Honored Contributor
Solution

Re: file size alert

Hi,

just an idea:

FILE=test
while :
do
ls -nodg $FILE | awk '{if($3 > 1800000000)exit 0; exit 1}'
if [ $? = 0 ]
then
echo "File $FILE has reached 1800000000 Bytes !"|mail user@domain
exit 0
fi
sleep 60
done

Regards
Chris Vail
Honored Contributor

Re: file size alert

The easiest way to do this is to write a script to check this, and run it in cron. Here's a quickie

/usr/bin/ksh
FFILE=/somepath/somefile
FSIZE=`ll $FFILE|awk '{ print $5 }'`
CSIZE=`echo $FSIZE/1048576|bc`
if test "CSIZE" -gt "2048"
then
echo "$FFILE is now larger than 2GB"|mailx -s "$FFILE Size error" root@yourhost
fi

Dividing FSIZE by 1045876 gets around the fact that the test command freaks out when dealing with numbers larger than 2,147,483,647 (2^30-1).

You could put this in a continuous loop by and not using cron by inserting the above lines between:

while true
do
.......(insert above lines here)
.......sleep 60 (or some other number)
done


Good Luck
Chris








James Odak
Valued Contributor

Re: file size alert

depending on how you want to do it


#1

while true
do
SIZE=ll /etc/fstab|cut -c 35-44

if [[ $SIZE -ge ##### ]]
then
cat warningmessagefile |sendmail -v you@your.mail
break
fi
done


this will constantly till the file passes the limmit you set (#####) then mail you 1x and stop


or you can make a cron job

SIZE=ll /etc/fstab|cut -c 35-44

if [[ $SIZE -ge ##### ]]
then
cat warningmessagefile |sendmail -v you@your.mail
fi

and schedule it to run at whatever intervals you like



Jim




Jose Mosquera
Honored Contributor

Re: file size alert

Hi,

EMAIL=your_email@domain
FILE=your_file_name
LIMIT=1500000000
SIZE=`ls -l $FILE|awk '{ print $5 }'`
if [ $SIZE -gt $LIMIT ]
then
mailx -s "Message Subject" $EMAIL < /dev/null
fi

Rgds.
Steve Labar
Valued Contributor

Re: file size alert


#!/usr/bin/sh
FILE="your_file"
MAX=2000000 # 2 gig measured in kbytes
SIZE=`du -sk $FILE`
if [ $SIZE -ge $MAX ] ; then
echo "$FILE too large"
fi

You might want to change max size to catch before it actually reaches 2 gig, maybe 1990000. You could cron this script every couple of minutes.

Steve
Michael Campbell
Trusted Contributor

Re: file size alert

thats great - thanks!