<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Redirecting standard error within a for loop in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971313#M95323</link>
    <description>I am assuming that you do not want stderr to also go through the grep.  Many ways to do this, but I would try:&lt;BR /&gt;&lt;BR /&gt;for i in `ioscan -fnC disk | grep /dev/dsk| awk '{print $1}'`&lt;BR /&gt;do&lt;BR /&gt;pvdisplay $i | grep Cannot&lt;BR /&gt;done 2&amp;gt;&amp;amp;1 | more&lt;BR /&gt;</description>
    <pubDate>Wed, 28 Mar 2007 11:20:29 GMT</pubDate>
    <dc:creator>Bob E Campbell</dc:creator>
    <dc:date>2007-03-28T11:20:29Z</dc:date>
    <item>
      <title>Redirecting standard error within a for loop</title>
      <link>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971311#M95321</link>
      <description>Hello all,&lt;BR /&gt;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.&lt;BR /&gt;Here is what I'm trying to do:&lt;BR /&gt;for i in `ioscan -fnC disk | grep /dev/dsk| awk '{print $1}'`&lt;BR /&gt;do&lt;BR /&gt;pvdisplay $i |  grep Cannot | more&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;Putting the standard 2&amp;gt;&amp;amp;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.&lt;BR /&gt;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.&lt;BR /&gt;Can this be done? &lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Travis</description>
      <pubDate>Wed, 28 Mar 2007 11:12:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971311#M95321</guid>
      <dc:creator>Travis Harp_1</dc:creator>
      <dc:date>2007-03-28T11:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Redirecting standard error within a for loop</title>
      <link>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971312#M95322</link>
      <description>"Since the output that I'm looking for is an error from pvdisplay "pvdisplay:..."&lt;BR /&gt;&lt;BR /&gt;If that's true, redirect the error from pvdisplay to stdout.&lt;BR /&gt;&lt;BR /&gt;pvdisplay $1 2&amp;gt;&amp;amp;1 | grep .....&lt;BR /&gt;&lt;BR /&gt;outta get it</description>
      <pubDate>Wed, 28 Mar 2007 11:17:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971312#M95322</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2007-03-28T11:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Redirecting standard error within a for loop</title>
      <link>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971313#M95323</link>
      <description>I am assuming that you do not want stderr to also go through the grep.  Many ways to do this, but I would try:&lt;BR /&gt;&lt;BR /&gt;for i in `ioscan -fnC disk | grep /dev/dsk| awk '{print $1}'`&lt;BR /&gt;do&lt;BR /&gt;pvdisplay $i | grep Cannot&lt;BR /&gt;done 2&amp;gt;&amp;amp;1 | more&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Mar 2007 11:20:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971313#M95323</guid>
      <dc:creator>Bob E Campbell</dc:creator>
      <dc:date>2007-03-28T11:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Redirecting standard error within a for loop</title>
      <link>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971314#M95324</link>
      <description>Try this:&lt;BR /&gt;&lt;BR /&gt;for i in $(ioscan -fnC disk | grep /dev/dsk| awk '{print $1}')&lt;BR /&gt;do&lt;BR /&gt;pvdisplay ${i} &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;[ $? = 0 ] &amp;amp;&amp;amp; echo "${i} disk in use" || echo "${i} disk not in use"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;First, notice I replaced you back-ticks (the ``) with the $() construct.  That is much easier to read.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Mar 2007 11:28:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971314#M95324</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2007-03-28T11:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Redirecting standard error within a for loop</title>
      <link>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971315#M95325</link>
      <description>By the way, you would be better off using 'ioscan -kfnC disk' rather than '-fnC disk'.  Adding the '-k' tells ioscan to use what the kernel thinks is there and so it doesn't have to rescan your entire system.  The ioscan will be much faster this way.</description>
      <pubDate>Wed, 28 Mar 2007 11:30:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971315#M95325</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2007-03-28T11:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Redirecting standard error within a for loop</title>
      <link>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971316#M95326</link>
      <description>Hi Travis:&lt;BR /&gt;&lt;BR /&gt;You certainly don't need to use 'grep' AND 'awk' to match patterns!   That's a waste of a process.&lt;BR /&gt;&lt;BR /&gt;# ioscan -kfnC disk|awk '/dev\/dsk\// {print $1}'&lt;BR /&gt;&lt;BR /&gt;...will return the disk device files.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Mar 2007 12:39:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/redirecting-standard-error-within-a-for-loop/m-p/3971316#M95326</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-03-28T12:39:58Z</dc:date>
    </item>
  </channel>
</rss>

