Re: check filesystem usage script (201 Views)
Reply
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 1 of 7 (201 Views)
Accepted Solution

check filesystem usage script

Hello,

I have closed a previous thread and started this one as this should be more clear for what I require.

I want to create a script that prints the output to a file to be read by another program.

I want the filesystem usage to be recorded when a critical threshold and a warning threshold have been exceed.

here is a start to what i need ( this is on Linux)


DIR=/sysadmin/scripts/admin
LOG=$DIR/msgfile.out

WARN=70
CRIT=90


CMD=`df|awk 'NR>1 && !/\/proc$/ {print $7,$4}'|sed -e s/%//g -e s/' '/:/g`

FILESYS=`echo $CMD | cut -d":" -f1`
USED=`echo $CMD | cut -d":" -f2`

how can I create the output so the file looks something like:

WARNING ###########

/ is at 78%
/home is at 89%

CRITICAL ##########

/tmp is a 98%
/var is at 92%
hello
Honored Contributor
Yang Qin_1
Posts: 514
Registered: ‎10-23-2002
Message 2 of 7 (201 Views)

Re: check filesystem usage script

df on my HP server does not produce the same output as youlisted. I use bdf:

#!/bin/ksh

DIR=/sysadmin/scripts/admin
LOG=$DIR/msgfile.out

echo "####### WARNING ###########" > $LOG

bdf | grep -v "\/proc" | awk ' {print $5 " " $6} ' | sed 's/\%//'|awk '
{
if ( $1 > 50 )
if ( $1 < 80 )
print $2 " is at " $1 "%"
} ' >> $LOG

echo "####### CRITICAL ###########" >> $LOG

bdf | grep -v "\/proc" | awk ' {print $5 " " $6} ' | sed 's/\%//'|awk '
{
if ( $1 > 80 )
print $2 " is at " $1 "%"
} ' >> $LOG

exit


Yang
Honored Contributor
spex
Posts: 1,367
Registered: ‎05-14-1996
Message 3 of 7 (201 Views)

Re: check filesystem usage script

Hello,

I make use of Bill Hassell's bdfmegs script to ensure 'bdf' output contains one line per filesystem.

# cat fs_warn.awk
BEGIN {
match=0;
}
{
if (NR > 1)
{
sub(/\%/,"");
}
if ($5>=70 && $5<90)
{
if (matched==0)
{
print "####### WARNING #######";
matched=1;
}
print $6, "is at", $5"%";
}
}

# cat fs_crit.awk
BEGIN {
match=0;
}
{
if (NR > 1)
{
sub(/\%/,"");
}
if ($5>=90)
{
if (matched==0)
{
print "####### CRITICAL #######";
matched=1;
}
print $6, "is at", $5"%";
}
}

# bdfmegs.sh | awk -f fs_warn.awk > logfile
# bdfmegs.sh | awk -f fs_crit.awk >> logfile

PCS
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 4 of 7 (201 Views)

Re: check filesystem usage script

how can i get the $VAR to be used with the awk statement:

WARN=10
CRIT=40

df|awk 'NR>1 && !/\/proc$/ {print $7,$4}'|sed 's/\%//'|awk '
{
if ( $2 > $WARN )
if ( $2 < $CRIT )

currently i have to use :


if ( $2 > 10 )
if ( $2 < 40 )

i have created a file with the various limits for $WARN and $CRIT therefore the setting entered into the awk will not always be the case.

thanks in advance

hello
Honored Contributor
Yang Qin_1
Posts: 514
Registered: ‎10-23-2002
Message 5 of 7 (201 Views)

Re: check filesystem usage script

df|awk 'NR>1 && !/\/proc$/ {print $7,$4}'|sed 's/\%//'|awk -v WARN=10 -v CRIT=40 '
{
if ( $2 > WARN )
if ( $2 < CRIT )


Yang
Honored Contributor
Yang Qin_1
Posts: 514
Registered: ‎10-23-2002
Message 6 of 7 (201 Views)

Re: check filesystem usage script

Or you may want this one:

WARN=10
CRIT=40

df|awk 'NR>1 && !/\/proc$/ {print $7,$4}'|sed 's/\%//'|awk -v v1=$WARN -v v2=$CRIT '
{
if ( $2 > v1 )
if ( $2 < v2 )


Yang
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 7 of 7 (201 Views)

Re: check filesystem usage script

Thanks man - thats it!

Chris
hello
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.