Operating System - HP-UX
1833187 Members
2465 Online
110051 Solutions
New Discussion

Ignore inactive vg in script

 
SOLVED
Go to solution
rleon
Regular Advisor

Ignore inactive vg in script

Hi everyone

I am trying to write a script to check for unavailable and stale drives.

#!/usr/bin/sh

for vg in `vgdisplay | grep "VG Name" | awk -F"/" '{print $3}'`
do
if vgdisplay -v $vg | grep -q stale > /dev/null 2>&1
then
vg_msg="`hostname`:Volume Group $vg has a stale Logical Volume."
fi

if vgdisplay -v $vg | grep "PV Status" | grep -q unavailable > /dev/null 2>&1
then
vg_msg="`hostname`:Volume Group $vg has unavailable disk."
fi

done

echo "$vg_msg"


The problem that I am having is that if I run across a vg that is not active I get the following output even though I am just looking for the vgname.

In this case I even did a grep -v to ignore vgdisplay but I was not able to exclude the inactive vg.

# vgdisplay | grep -v vgdisplay | grep "VG Name" | awk -F"/" '{print $3}'
vgdisplay: Volume group not activated.
vgdisplay: Cannot display volume group "/dev/aroot".
appsvg00
vg00

Any ideas would be helpful.

Thanks
3 REPLIES 3
Tim Nelson
Honored Contributor
Solution

Re: Ignore inactive vg in script

I believe that error is outputed on std-err..

redirect it

vgdisplay -v 2>/dev/null|grep blah etc.. etc..
Dennis Handly
Acclaimed Contributor

Re: Ignore inactive vg in script

>did a grep -v to ignore vgdisplay but I was not able to exclude the inactive vg.

Is this output going to stderr? You either want to send it to /dev/null or redirect it to stdout.
vgdisplay 2> /dev/null | grep -v vgdisplay | ...

>vgdisplay -v $vg | grep -q stale > /dev/null 2>&1

No need to redirect the non-existent grep output. You may what to redirect vgdisplay stderr:
vgdisplay -v $vg 2> /dev/null | grep -q stale
rleon
Regular Advisor

Re: Ignore inactive vg in script

thanks that did it.