Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Newbie Brain Freeze Simple If Question

SOLVED
Go to Solution
Super Advisor

Newbie Brain Freeze Simple If Question

I'm doing a bdf on my HP-UX 11.i box. I then awk out the % used ($1) and the mount point($2). I want an if statment that goese something like this.
If $1 is > 80% AND (!grep "/opt/sc" $2) then do something

Can anyone help me with this. I've got brain freeze.

Thanks

Scott
1 ACCEPTED SOLUTIONS
Honored Contributor Honored Contributor

Re: Newbie Brain Freeze Simple If Question

bdf display will give format as,
Filesystem kbytes used avail %used Mounted on

so that,

we will be having $1 - %
$2 - FS then,

bdf | awk '!/^Filesystem/ { print $5" "$1 }' | while read per fs; do

if [[ $per -gt 80% && $fs = "/opt/sc" ]]
then

# do something
fi
done

Else simply with awk as,

bdf | awk '!/^Filesystem/ { if ( $5 > 80 && $1 == "/opt/sc") }'

HTH.

Easy to suggest when don't know about the problem!
7 REPLIES
Honored Contributor Honored Contributor

Re: Newbie Brain Freeze Simple If Question

if [ $1 -gt 80 -a $2 != "/opt/sc" ]; then

whatever you want.

Anil
There is no substitute to HARDWORK
Super Advisor

Re: Newbie Brain Freeze Simple If Question

$2 will contain
/patrol
/opt
/opt/supra2/savelog
/opt/supra2/dbutil
/opt/sct2/dbl1
/opt/sct2/db01
/opt/sct1/dbl1
/opt/sct1/db01
/opt/scp1/dbl2

This is why I want to grep $2 and look for "/opt/sc". Can this be included in the statement?

Scott
Honored Contributor Honored Contributor

Re: Newbie Brain Freeze Simple If Question

try this:

if echo $2|grep "/opt/sc">/dev/null; then
if [[ "$1" -gt 80 ]]; then



mark

the future will be a lot like now, only later
Honored Contributor Honored Contributor

Re: Newbie Brain Freeze Simple If Question

test "$1 -gt 80 -a $2 != "/opt/sc"" && "whatever you want"

Anil
There is no substitute to HARDWORK
Honored Contributor Honored Contributor

Re: Newbie Brain Freeze Simple If Question

for in i in $(echo $2)
do
test "$1 -gt 80 -a $2 != "/opt/sc"" && "whatever you want"test "
done

Anil
There is no substitute to HARDWORK
Honored Contributor Honored Contributor

Re: Newbie Brain Freeze Simple If Question

bdf display will give format as,
Filesystem kbytes used avail %used Mounted on

so that,

we will be having $1 - %
$2 - FS then,

bdf | awk '!/^Filesystem/ { print $5" "$1 }' | while read per fs; do

if [[ $per -gt 80% && $fs = "/opt/sc" ]]
then

# do something
fi
done

Else simply with awk as,

bdf | awk '!/^Filesystem/ { if ( $5 > 80 && $1 == "/opt/sc") }'

HTH.

Easy to suggest when don't know about the problem!
Highlighted
Super Advisor

Re: Newbie Brain Freeze Simple If Question

Here is what I am doing. I'm running bdf to a file for multiple uses. My output goes to an html file that gives us a dashboard look at our system health. I we have yellow or red lights, we know there are issues we need to look at. We are removing some Oracle filesystems from the check because they are at 100% but we are told they are fine.

Thanks for all the input and now for my sloppy code.

bdf > /home/sysadmin/get_diskusage
awk '!/^Filesystem/ { print $5" "$6 }' /home/sysadmin/get_diskusage | while read preper fs; do
per=`echo "$preper" | awk '{print $1}' | cut -f1 -d'%'`
dugreen=1
if [ $per -gt 85 ]
then if [ `echo ${fs} | grep "/opt/sc"` ]
then dugreen=1
else duyellow=1
fi
fi

if [ $per -gt 90 ]
then if [ `echo ${fs} | grep "/opt/sc"` ]
then dugreen=1
else dured=1
fi
fi
done

if [ $dured ]
then IMG=redlight
elif [ $duyellow ]
then IMG=yellowlight
else IMG=greenlight
fi

print_image