Bug 487037 - Output from vgdisplay is not going to stdout when the volume group doesn't exist.
Output from vgdisplay is not going to stdout when the volume group doesn't ex...
Status: CLOSED DUPLICATE of bug 470560
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: lvm2 (Show other bugs)
All Linux
low Severity medium
: rc
: ---
Assigned To: Milan Broz
Cluster QE
Depends On:
  Show dependency treegraph
Reported: 2009-02-23 14:19 EST by Darryl L. Pierce
Modified: 2015-06-21 20:06 EDT (History)
9 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2009-02-24 04:24:07 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Darryl L. Pierce 2009-02-23 14:19:33 EST
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):

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 04:24:07 EST
vgdisplay status  bug is fixed in upstream lvm2 (2.02.43) and will be in RHEL5.4
 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
# vgdisplay x; echo $?
  Volume group "x" not found

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

Note You need to log in before you can comment on or make changes to this bug.