1833838 Members
2377 Online
110063 Solutions
New Discussion

Re: Shell Script

 
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
2 REPLIES 2
Rodney Hills
Honored Contributor

Re: Shell Script

Raje,

You could use perl for the whole thing.

while(<>) {
chomp;
if (/^\d+$/) {
chomp($n2=<>);
$pct=100*$n2/$_;
push(@db,sprintf "%3d %s",$pct,$db) if $pct > 80;
} else {
$db=$_;
}
}
if (scalar @db) {
open(OUT,"|mailx -s 'Some databases are over 80%' youremail\@yourhome.com'");
print OUT $_,"\n" foreach @db;
close(OUT);
}

HTH

-- Rod Hills
There be dragons...
Jean-Louis Phelix
Honored Contributor

Re: Shell Script

Once again, just in case ...

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 ...)