Operating System - HP-UX
1835414 Members
2997 Online
110078 Solutions
New Discussion

Re: script to display unavailable/stale lv's in vgdisplay -v output

 
SOLVED
Go to solution
Mike Kapsak
Advisor

script to display unavailable/stale lv's in vgdisplay -v output

Can someone provide a script that will report on unavailable/stale logical volumes in a vgdisplay -v command and display the system name, the LV Name, and the LV Status on one line.

Thank you
18 REPLIES 18
harry d brown jr
Honored Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output


vgdisplay -v | grep -i stale


live free or die
harry
Live Free or Die
steven Burgess_2
Honored Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output

Hi

vgdisplay -v /dev/vg0x | grep -i stale

HTH

Steve
take your time and think things through
Ian Dennison_1
Honored Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output

Heres the structure, fill in the blanks,...

vgdisplay -v |awk '$0 ~ /LV Name/ {lv=$3} $0 ~ /LV Status/ {print lv" "$4}' >/tmp/file1

while read lv status
do

COUNT=`lvdisplay -v /dev/vgNAME/$lv |grep stale |wc -l`

print $lv" "$COUNT" "$status

done
The read statement may need tuning or correcting.

Share and Enjoy! Ian
Building a dumber user
MANOJ SRIVASTAVA
Honored Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output

vgdisplay -v | grep stale



Manoj Srivastava
S.K. Chan
Honored Contributor
Solution

Re: script to display unavailable/stale lv's in vgdisplay -v output

I wrote a script that does more than that. Invoke ..
# ./lvmstat
for full usage. You may find it useful. Open it with wordpad.
harry d brown jr
Honored Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output


Being that you haven't really explained why the answers provided aren't what you expected, then how about something like this:


vgdisplay -v | grep -i -e stale -e "LV NAME"


live free or die
harry

Live Free or Die
Mike Kapsak
Advisor

Re: script to display unavailable/stale lv's in vgdisplay -v output

I appreciate everyone's response to my question. I asked because I am not fluent in scripting. S.K. supplied a nice script, but what I'm really looking for is a simple report that contains, line by line, the system name, VG Name, VG Status, LV Name, and LV Status, distribute this script to all servers and put it in cron. With that info I want to be able to mail and/or page interested parties.

Thanks
harry d brown jr
Honored Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output

scope creep. Now that we have a clearer statement of the problem, and you seem to have an answer, do you still need help??

live free or die
harry
Live Free or Die
Pete Randall
Outstanding Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output

Mike,

Being non-fluent (is that affluent?) in scripting myself, I'll just throw in a suggestion. How about a script that greps the vgdisplay output for stale (or any other "bad" state) and, if found, emails whomever a brief message to check machine fubar's lvol status because something's amiss?

Is that more what you had in mind?

Pete

Pete
Mike Kapsak
Advisor

Re: script to display unavailable/stale lv's in vgdisplay -v output

In the future I will try to elaborate on my question. I appreciate the quick responses each time I post a message. Again thanks for helping me.

Mike Kapsak
James R. Ferguson
Acclaimed Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output

Hi Mike:

Crude and quick:

#!/usr/bin/sh
vgdisplay -v| awk -v HOST=$(hostname) '/VG Name/ {VG=$3}
/VG Status/ {VSTA=$3}
/LV Name/ {LV=$3}
/LV Status/ {LSTA=$3;print HOST,VG,VSTA,LV,LSTA}
'
exit 0

Regards!

...JRF...
S.K. Chan
Honored Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output

A simple much one ..

#! /usr/bin/ksh
#
HOST=$(hostname)

print "$HOST\n"
for vg in $(vgdisplay|grep -E 'VG Name'|awk '{print $3}')
do
print "$vg\n"
VGSTAT=$(vgdisplay $vg|grep -E 'VG Status')
print "$VGSTAT\n"
LVSTAT=$(vgdisplay -v $vg|sed 's/^[ \t]*//'|grep -E 'LV Name|LV Status')
print "$LVSTAT\n"
done
MANOJ SRIVASTAVA
Honored Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output

Hi Mike


here is one script which will help you .



Manoj Srivastava
Mike Kapsak
Advisor

Re: script to display unavailable/stale lv's in vgdisplay -v output

Pete,

You're summation is correct, but i don't know how to script it. The report would look like this and only report unavailable or stale, put it into cron at a given time, and mail anyone who wants it.

"System Name"
VGName VGStatus LVName LVStatus


Mike Kapsak
Pete Randall
Outstanding Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output

Okay, Mike - you asked for it. Here's my attempt at a script. Maybe someone will see the simple approach we're attempting to take here and polish it for you, but I think this is the basic idea:


if [ `vgdisplay -v |grep -i stale | wc -l` -gt 0 ]
then
echo "Server $hostname has an LVM issue" > file.oops
elm -s "Oops" joeblow@wherever.com < file.oops
fi


Good Luck,

Pete

Pete
Mike Kapsak
Advisor

Re: script to display unavailable/stale lv's in vgdisplay -v output

Pete,

The script looks simple enough. Now I need to work on making a volume stale in order to test.

Thank you,
Mike Kapsak
steven Burgess_2
Honored Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output

Hi Mike

There is a script available called lvmcollect that gives you a full overview of your lvm system

You can get a copy on the last reply from Patrick in this thread

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xf33fec08252fd611abd50090277a778c,00.html

HTH

Steve
take your time and think things through
Pete Randall
Outstanding Contributor

Re: script to display unavailable/stale lv's in vgdisplay -v output

Mike,

For my own testing purposes, I grepped for "syncd" rather than stale. There's a lot of "syncd" lvols out there.

Pete

Pete