Bug 487037

Summary: Output from vgdisplay is not going to stdout when the volume group doesn't exist.
Product: Red Hat Enterprise Linux 5 Reporter: Darryl L. Pierce <dpierce>
Component: lvm2Assignee: Milan Broz <mbroz>
Status: CLOSED DUPLICATE QA Contact: Cluster QE <mspqa-list>
Severity: medium Docs Contact:
Priority: low    
Version: 5.3CC: agk, dwysocha, edamato, heinzm, jbrassow, mbroz, prockai, pvrabec, tross
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-02-24 09:24:07 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Darryl L. Pierce 2009-02-23 19:19:33 UTC
Description of problem:
Within a script I attempt to capture the output of "vgdisplay HostVG" and check it for the phrase "not found" in order to verify the volume group exists. I used the following snippet:

verify=$(vgdisplay HostVG)

When the volume group is present then $verify contains the output. However, when the volume group does not exist then $verify is empty and all output is sent solely to the console.

Version-Release number of selected component (if applicable):
lvm2-2.02.40-6.el5.x86_64

How reproducible:
Every time.

Steps to Reproduce:
1. attempt to assign to a variable the output for vgdisplay on a non-existent volume group
  
Actual results:
The variable is an empty string.

Expected results:
The output from the vgdisplay command.

Additional info:
Additionally, the return code for vgdisplay is 0. This may not be an error condition, but it would make scripting run better if we could check the return code to see if the volume group existed.

Comment 1 Milan Broz 2009-02-24 09:24:07 UTC
vgdisplay status  bug is fixed in upstream lvm2 (2.02.43) and will be in RHEL5.4
Changelog:
 Exit with non-zero status from vgdisplay if couldn't show any requested VG.

Better use "vgs" command here, status is correct here already:
# vgs x; echo $?
  Volume group "x" not found
5
# vgdisplay x; echo $?
  Volume group "x" not found
0

Error messages are printed to stderr now by default, so if you need its output, sipmply redirect it:

output=$(vgs name 2>&1)

*** This bug has been marked as a duplicate of bug 470560 ***