1752407 Members
5590 Online
108788 Solutions
New Discussion юеВ

Re: script

 
SOLVED
Go to solution
kholikt
Super Advisor

script

I have written a script to monitor /var file system.

If it is more than 85% an email will be send.

[root@myserver]/root/home/root $bdf | grep var
/dev/vg00/lvol8 5572685 4429938 585478 88% /var
[root@myreserver]/root/home/root $bdf | grep var | awk '{print $5}'
88%

Once I get the value of 88% from the awk. How could I do a numeric comparision. Should I take out the "%" symbol.


abc
5 REPLIES 5
Scott Van Kalken
Esteemed Contributor
Solution

Re: script

yup

take out the % symbol.

sed 's/%//g' will do this for you.

That's a single quote pointing -> (that way).

you can probably do the entire thing in sed (or awk).

my solution would spawn a lot of shells, because you're using grep, awk and sed. So it's probably not ideal.

Scott.
kholikt
Super Advisor

Re: script

#!/usr/bin/sh
for i in `bdf | grep arch | awk '{print $4}' | sed 's/%//g'`
do
echo $i
if [ $i -gt 90 ]
then
echo "more than 20%"
fi
done

Hi This is what my script will do check some filesystem that is more than 90%.

I used the output of bdf 4096000 884400 3186560 22% /oracle/TRD/saparch
4096000 306480 3759976 8% /oracle/TRA/saparch
4096000 53104 4011376 1% /oracle/TBD/saparch
4096000 270583 3586394 7% /oracle/SBD/saparch

For the for loop how could I also print out the filesystem name that is more than 90%

The current script can only find out filesystem that is more than 90% but it won't give the filesystem name.
abc
curt larson_1
Honored Contributor

Re: script

using "4096000 306480 3759976 8% /oracle/TRA/saparch" as the output of your bdf, try this

bdf |
awk '/arch/ {
percent=$4;
filesystem=$5;
percentage=$4;
sub(%,"",percentage);

if (percentage > "90") printf("%5s%s\n",percent,filesystem);
}'
kholikt
Super Advisor

Re: script

I have tried but it just returned this error

syntax error The source line is 5.
The error context is
>>> sub(% <<< ,"",percentage);
awk: The statement cannot be correctly parsed.
The source line is 5.
abc
Andreas Voss
Honored Contributor

Re: script

Hi,

the % must be quoted,
replace

sub(%,"",percentage);

with

sub("%","",percentage);

Regards