1833275 Members
2829 Online
110051 Solutions
New Discussion

Shell Script

 
SOLVED
Go to solution
Sanjiv Sharma_1
Honored Contributor

Shell Script

Hi,

I am writing a shell script which will give me the database free space information and alert. I am getting the following output :

ds1dbs
5000000
991156

tmpdbs
1000000
999944

c3dbs
2000000
932508

s2dbs
5000000
1860968

rootdbs
512000
8815

testdbs
4000000
1087746

My requirement is that the script will calculate the percentage for all the above database like for testdbs:
1087746/4000000*100=27.19%.

If this percentage is more then 80% then it should send a mail to me?

Can anyone help me to get started?

Thanks,
Raje.
Everything is possible
7 REPLIES 7
Scott Van Kalken
Esteemed Contributor

Re: Shell Script

percent=$(expr 100 \* $currentblocks / $maxblocks)
Christian Gebhardt
Honored Contributor
Solution

Re: Shell Script

Try this

awk '{line[NR]=$0}
END {
for (i=0;i<=NR;i++) {
if ( line[i] ~ /dbs/ ) {
printf("%s %2.2f%\n",line[i],line[i+2]/line[i+1]*100)
}
}
}
' filename

Chris
H.Merijn Brand (procura
Honored Contributor

Re: Shell Script

l1:/tmp 111 > perl -lne 'BEGIN{$/=undef}for(split/\n\n/){($d,$t,$u)=split/\n/;print"$d\t$t\t$u\t",100*$u/$t}' < output
ds1dbs 5000000 991156 19.82312
tmpdbs 1000000 999944 99.9944
c3dbs 2000000 932508 46.6254
s2dbs 5000000 1860968 37.21936
rootdbs 512000 8815 1.7216796875
testdbs 4000000 1087746 27.19365
l1:/tmp 112 >
Enjoy, Have FUN! H.Merijn
Jean-Louis Phelix
Honored Contributor

Re: Shell Script

Hello,

using shell ... cat your input to this script :

#!/usr/bin/sh

while read DBS
do
read BLOCKS
read USED
read
PERC=$(($USED \* 100 / $BLOCKS))
[ "$PERC" -gt 80 ] &&
{
echo "\n$DBS has ${PERC}% blocks used\n" | mailx -s "Free space in $DBS" phelix
}
done

And you will receive :

Date: Thu, 17 Oct 2002 09:16:30 +0200 (METDST)
From: Jean-Louis Phelix
To: phelix
Subject: Free space in tmpdbs

tmpdbs has 99% blocks used
It works for me (© Bill McNAMARA ...)
john korterman
Honored Contributor

Re: Shell Script

Hi,
try the attached script with your input file as $1

regards,
John K.
it would be nice if you always got a second chance
harry d brown jr
Honored Contributor

Re: Shell Script

Raje,

Why did you give Jean-Louis Phelix only three (3) points and nothing to john korterman yet for what are obiviously correct answers?

Is there something they missed?

live free or die
harry
Live Free or Die
Leslie Chaim
Regular Advisor

Re: Shell Script

TIMTOWTDI!

How about this:

perl -na00e 'printf "$F[0]:%.2f%%\n", $F[2]/$F[1]*100' database_output_file

Cheers,
Leslie
If life serves you lemons, make lemonade