Operating System - Linux
1748027 Members
4392 Online
108757 Solutions
New Discussion юеВ

Re: check filesystem usage script

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

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
6 REPLIES 6
Yang Qin_1
Honored Contributor
Solution

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
spex
Honored Contributor

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
lawrenzo_1
Super Advisor

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
Yang Qin_1
Honored Contributor

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
Yang Qin_1
Honored Contributor

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
lawrenzo_1
Super Advisor

Re: check filesystem usage script

Thanks man - thats it!

Chris
hello