Newbie Brain Freeze Simple If Question (285 Views)
Reply
Super Advisor
Scott Frye_1
Posts: 272
Registered: ‎05-14-2004
Message 1 of 8 (285 Views)
Accepted Solution

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
Honored Contributor
RAC_1
Posts: 5,920
Registered: ‎03-21-2002
Message 2 of 8 (285 Views)

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
Scott Frye_1
Posts: 272
Registered: ‎05-14-2004
Message 3 of 8 (285 Views)

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
Mark Greene_1
Posts: 1,422
Registered: ‎06-26-2001
Message 4 of 8 (285 Views)

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
RAC_1
Posts: 5,920
Registered: ‎03-21-2002
Message 5 of 8 (285 Views)

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
RAC_1
Posts: 5,920
Registered: ‎03-21-2002
Message 6 of 8 (285 Views)

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
Muthukumar_5
Posts: 4,030
Registered: ‎06-09-2004
Message 7 of 8 (285 Views)

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!
Super Advisor
Scott Frye_1
Posts: 272
Registered: ‎05-14-2004
Message 8 of 8 (285 Views)

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