<?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: loop on ps -ef output in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250541#M52489</link>
    <description>$(ps -ef | grep -v grep | awk '{print substr($9,10,length($9) - 10)}')&lt;BR /&gt;&lt;BR /&gt;note:&lt;BR /&gt;grep -v grep : to not grab the greb command&lt;BR /&gt;&lt;BR /&gt;substr of string $9, starting at position 10, to position 11 to second last character.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 05 Aug 2010 21:01:39 GMT</pubDate>
    <dc:creator>Wilfred Chau_1</dc:creator>
    <dc:date>2010-08-05T21:01:39Z</dc:date>
    <item>
      <title>loop on ps -ef output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250539#M52487</link>
      <description>Hi Guys&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I'm doing this&lt;BR /&gt;&lt;BR /&gt;for databases in $(ps -ef | grep -i ora_pmon | awk '{print $9}')&lt;BR /&gt;&amp;gt;  do&lt;BR /&gt;&amp;gt;  echo $databases&lt;BR /&gt;&amp;gt;  done&lt;BR /&gt;Result is:&lt;BR /&gt;&lt;BR /&gt;ora_pmon_WSLPREP1&lt;BR /&gt;ora_pmon_HCMPRE21&lt;BR /&gt;ora_pmon_WMTPREP1&lt;BR /&gt;ora_pmon_RATPREP1&lt;BR /&gt;-i&lt;BR /&gt;ora_pmon_PSCPREP1&lt;BR /&gt;ora_pmon_AUSTRNG1&lt;BR /&gt;ora_pmon_AUSPREP1&lt;BR /&gt;&lt;BR /&gt;1. How to Eliminate the -i (in the loop because grep command is running)&lt;BR /&gt;&lt;BR /&gt;2. How to eliminate "ora_pmon_" and "1" to have only my instance name like this:&lt;BR /&gt;&lt;BR /&gt;WSLPREP&lt;BR /&gt;HCMPRE2&lt;BR /&gt;WMTPREP&lt;BR /&gt;RATPREP&lt;BR /&gt;PSCPREP&lt;BR /&gt;AUSTRNG&lt;BR /&gt;AUSPREP&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Let me know if you have a solution.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance&lt;BR /&gt;Regards&lt;BR /&gt;Den</description>
      <pubDate>Thu, 05 Aug 2010 18:00:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250539#M52487</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2010-08-05T18:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: loop on ps -ef output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250540#M52488</link>
      <description>grep -i [o]ra_pmon&lt;BR /&gt;&lt;BR /&gt;echo $databases |awk -F'_' '{print $3}'</description>
      <pubDate>Thu, 05 Aug 2010 20:47:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250540#M52488</guid>
      <dc:creator>Kevin Wright</dc:creator>
      <dc:date>2010-08-05T20:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: loop on ps -ef output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250541#M52489</link>
      <description>$(ps -ef | grep -v grep | awk '{print substr($9,10,length($9) - 10)}')&lt;BR /&gt;&lt;BR /&gt;note:&lt;BR /&gt;grep -v grep : to not grab the greb command&lt;BR /&gt;&lt;BR /&gt;substr of string $9, starting at position 10, to position 11 to second last character.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Aug 2010 21:01:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250541#M52489</guid>
      <dc:creator>Wilfred Chau_1</dc:creator>
      <dc:date>2010-08-05T21:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: loop on ps -ef output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250542#M52490</link>
      <description>I think I missed the ora_pmon part, here you go again.&lt;BR /&gt;&lt;BR /&gt;$(ps -ef |grep -i ora_pmon | grep -v grep | awk '{print substr($9,10,length($9) - 10)}')&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Aug 2010 21:29:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250542#M52490</guid>
      <dc:creator>Wilfred Chau_1</dc:creator>
      <dc:date>2010-08-05T21:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: loop on ps -ef output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250543#M52491</link>
      <description>&lt;!--!*#--&gt;As pointed out above, you can avoid finding grep in the ps listing by messing with shell expansion a bit and adding [] around the first letter.&lt;BR /&gt;&lt;BR /&gt;There's no real reason to call grep multiple times, nor even to call awk over and over again just for simple string manipulation. Here's one way to do it:&lt;BR /&gt;--&lt;BR /&gt;#! /bin/bash&lt;BR /&gt;&lt;BR /&gt;for database in $(ps -ef |grep [o]ra_pmon); do&lt;BR /&gt;  printf '%s\n' "${database##*_}"&lt;BR /&gt;done&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;This way, you only run 'ps' once and 'grep' once, and printf is a shell builtin in bash (even if there is a binary printf in the filesystem, bash won't use it unless you specify the full pathname.)You could probably do the whole thing with shell builtins and the /proc filesystem, but the benefit would be negligible in most cases.</description>
      <pubDate>Thu, 05 Aug 2010 22:27:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250543#M52491</guid>
      <dc:creator>macosta</dc:creator>
      <dc:date>2010-08-05T22:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: loop on ps -ef output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250544#M52492</link>
      <description>Hm, the above was untested, so I'm not sure the loop will work like I initially thought.&lt;BR /&gt;&lt;BR /&gt;You might try this:&lt;BR /&gt;--&lt;BR /&gt;#! /bin/bash&lt;BR /&gt;&lt;BR /&gt;ps -ef |grep [o]ra_pmon | while read db; do&lt;BR /&gt;  printf '%s\n' "${db##*_}"&lt;BR /&gt;done&lt;BR /&gt;--</description>
      <pubDate>Thu, 05 Aug 2010 22:38:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250544#M52492</guid>
      <dc:creator>macosta</dc:creator>
      <dc:date>2010-08-05T22:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: loop on ps -ef output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250545#M52493</link>
      <description>Hi Den&lt;BR /&gt;&lt;BR /&gt;This works for me notice  {print $8} you may need to adapt this to your output.&lt;BR /&gt;&lt;BR /&gt;for databases in $(ps -ef | grep -i [o]ra_pmon |grep -v "grep" | awk '{print $8}')&lt;BR /&gt;&amp;gt; do &lt;BR /&gt;&amp;gt; echo $databases&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&lt;BR /&gt;enjoy life.&lt;BR /&gt;&lt;BR /&gt;Jean-Pierre Huc</description>
      <pubDate>Fri, 06 Aug 2010 11:25:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250545#M52493</guid>
      <dc:creator>Huc_1</dc:creator>
      <dc:date>2010-08-06T11:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: loop on ps -ef output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250546#M52494</link>
      <description>Sorry got distracted and send the wrong version&lt;BR /&gt;&lt;BR /&gt;--------------------------&lt;BR /&gt;This works for me notice {print $8} you may need to adapt this to your output.&lt;BR /&gt;&lt;BR /&gt;for databases in $(ps -ef | grep -i [o]ra_pmon |grep -v "grep" | awk '{print substr($8,10)}')&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; echo $databases&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&lt;BR /&gt;--------------------------&lt;BR /&gt;if you need to replace $8 by $9 &lt;BR /&gt;&lt;BR /&gt;Hoping this is a little clear. &lt;BR /&gt;&lt;BR /&gt;enjoy life.&lt;BR /&gt;&lt;BR /&gt;Jean-Pierre Huc</description>
      <pubDate>Fri, 06 Aug 2010 12:43:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250546#M52494</guid>
      <dc:creator>Huc_1</dc:creator>
      <dc:date>2010-08-06T12:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: loop on ps -ef output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250547#M52495</link>
      <description>Excellent !&lt;BR /&gt;Thanks Guys</description>
      <pubDate>Fri, 06 Aug 2010 13:06:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250547#M52495</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2010-08-06T13:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: loop on ps -ef output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250548#M52496</link>
      <description>&lt;!--!*#--&gt;&amp;gt; [...] grep -i [o]ra_pmon |grep -v "grep"&lt;BR /&gt;&amp;gt; [...]&lt;BR /&gt;&lt;BR /&gt;So, you completely missed the reason for&lt;BR /&gt;using that "[o]" construct in "[o]ra_pmon"?&lt;BR /&gt;&lt;BR /&gt;&amp;gt; This works for me [...]&lt;BR /&gt;&lt;BR /&gt;You should try it without the second grep&lt;BR /&gt;command.</description>
      <pubDate>Fri, 06 Aug 2010 17:22:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/loop-on-ps-ef-output/m-p/5250548#M52496</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-08-06T17:22:06Z</dc:date>
    </item>
  </channel>
</rss>

