- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Redirecting standard error within a for loop
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2007 04:12 AM
тАО03-28-2007 04:12 AM
I'm trying to get a little for loop working that will quickly show me disks not in a volume group thus likely available for use.
Here is what I'm trying to do:
for i in `ioscan -fnC disk | grep /dev/dsk| awk '{print $1}'`
do
pvdisplay $i | grep Cannot | more
done
Since the output that I'm looking for is an error from pvdisplay "pvdisplay: Cannot display physical volume "/dev/dsk/c36t1d5"." it is not being piped to more.
Putting the standard 2>&1 after the grep within the for loop isn't working and the only solution I've found is to make this a script and redirect it on the command line after the script.
I'm really wanting something I can type in directly on the command line rather than going through the process of making a script on each server I need this info on.
Can this be done?
Thanks,
Travis
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2007 04:17 AM
тАО03-28-2007 04:17 AM
Re: Redirecting standard error within a for loop
If that's true, redirect the error from pvdisplay to stdout.
pvdisplay $1 2>&1 | grep .....
outta get it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2007 04:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2007 04:28 AM
тАО03-28-2007 04:28 AM
Re: Redirecting standard error within a for loop
for i in $(ioscan -fnC disk | grep /dev/dsk| awk '{print $1}')
do
pvdisplay ${i} > /dev/null 2>&1
[ $? = 0 ] && echo "${i} disk in use" || echo "${i} disk not in use"
done
First, notice I replaced you back-ticks (the ``) with the $() construct. That is much easier to read.
Now what this is doing is doing a pvdisplay and redirecting all output to /dev/null. The line after 'pvdisplay' if checking the pvdisplay return code (the $?). If the return code is 0, then pvdisplay was successful and the disk is likely in use. If the return code is not 0, then the disk is probably not in use.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2007 04:30 AM
тАО03-28-2007 04:30 AM
Re: Redirecting standard error within a for loop
- Tags:
- ioscan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2007 05:39 AM
тАО03-28-2007 05:39 AM
Re: Redirecting standard error within a for loop
You certainly don't need to use 'grep' AND 'awk' to match patterns! That's a waste of a process.
# ioscan -kfnC disk|awk '/dev\/dsk\// {print $1}'
...will return the disk device files.
Then, as Patrick suggested, use the return code from 'pvdisplay' to discern whether or not you have a "valid" device --- zero for success; non-zero for failure.
Regards!
...JRF...
- Tags:
- pvdisplay