Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Unix Q: Substring-ing an output.

RE: Unix Q: Substring-ing an output.

From: Mark J. Bobak <mark_at_bobak.net>
Date: Sun, 27 Oct 2002 20:48:37 -0800
Message-ID: <F001.004F4F2A.20021027204837@fatcity.com>


Hmm...good point. You know, I use this technique in various places. I never noticed that bug before, cause it will only appear if the database has been up less than 1 day. Guess it's time to do a bit of script auditing.

Ok, try this instead:
ps -ef|grep pmon|grep -v grep|cut -c49- |awk -F_ '{ 'print $3 }'

I replaced the first awk w/ cut. the -c option says to cut that output from position 49 to the end of the line. You may have to adjust the value from 49 to something else.

That ought to work for you.

-Mark
On Sun, 2002-10-27 at 22:53, Ross Collado wrote:
> Thanks Mark.
>
> Yes that helps, in a way. I could use good ol' awk to parse the last field!
> However, a slight problem in the ps -ef output. If I do what you have
> suggested on my 'ps -ef' output below, I would only get RMAN as it is the
> only one in field #8. All the rest are in field #9. All I need now is
> figure out how to cut the last field then pipe it to your awk command.
> Ok I'm getting somewhere!
>
> Rgds,
> Ross
>
>
>
> > -----Original Message-----
> > From: Mark J. Bobak [mailto:mark_at_bobak.net]
> > Sent: Monday, 28 October 2002 13:54
> > To: Multiple recipients of list ORACLE-L
> > Subject: Re: Unix Q: Substring-ing an output.
> >
> >
> > As is often the case, there are a million ways to do this. Given the
> > output listed, I'd do something like:
> >
> > ps -ef|grep pmon|grep -v grep|awk '{ print $8 }'|awk -F_ '{
> > print $3 }'
> >
> > ps -ef -- get the programs that are running
> > grep pmon -- get only those lines that have 'pmon' in them
> > grep -v grep -- drop out the line that has 'grep pmon'
> > awk '{ print $8 }' -- get the eighth column, the program name
> > awk -F_ '{ print $3 }' -- parse the program name on the '_' and return
> > the third field, the database name.
> >
> > Hope that helps,
> >
> > -Mark
> >
> > On Sun, 2002-10-27 at 20:43, Ross Collado wrote:
> > >
> > > Hi All,
> > >
> > > I want to feed my shell script with the names of currently running
> > > databases. I thought of using ps -ef|grep [p]mon. What I
> > got was the
> > > following:
> > > oracle 20113 1 0 Oct 25 ? 0:01 ora_pmon_TLDEV
> > > oracle 898 1 0 Jul 22 ? 0:06 ora_pmon_TLQA
> > > oracle 944 1 0 Jul 22 ? 0:07 ora_pmon_TLQAVAR
> > > oracle 19588 1 0 Oct 25 ? 0:00 ora_pmon_DBMON
> > > oracle 13509 1 0 12:16:13 ? 0:00 ora_pmon_RMAN
> > > oracle 20450 1 0 Oct 25 ? 0:00 ora_pmon_PRDINF
> > > oracle 13026 1 0 Oct 26 ? 0:00 ora_pmon_TLDVVAR
> > >
> > > What I wanted is get only the db name part eg. TLDEV, RMAN,
> > DBMON,etc. I
> > > don't want to rely on oratab file.
> > > I was thinking of using 'cut' to cut out the last field and
> > do some ${X##}
> > > (variable pattern substitution) to get to the dbname bit.
> > The trouble is
> > > the number of fields in a ps -ef output is not consistent.
> > As you can see
> > > I've just restarted RMAN and now it only has 8 fields as
> > compared to 9 for
> > > the others.
> > >
> > > Any suggestions? Or another way of doing it?
> > > Using KSH on Solaris 8.
> > >
> > > Thanks.
> > > Ross
> > --
> > --
> > Mark J. Bobak
> > Oracle DBA
> > mark_at_bobak.net
> > "It is not enough to have a good mind. The main thing is to use it
> > well."
> > -- Rene Descartes
> > --
> > Please see the official ORACLE-L FAQ: http://www.orafaq.com
> > --
> > Author: Mark J. Bobak
> > INET: mark_at_bobak.net
> >
> > Fat City Network Services -- 858-538-5051 http://www.fatcity.com
> > San Diego, California -- Mailing list and web hosting services
> > ---------------------------------------------------------------------
> > To REMOVE yourself from this mailing list, send an E-Mail message
> > to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> > the message BODY, include a line containing: UNSUB ORACLE-L
> > (or the name of mailing list you want to be removed from). You may
> > also send the HELP command for other information (like subscribing).
> >

-- 
--
Mark J. Bobak
Oracle DBA
mark_at_bobak.net
"It is not enough to have a good mind.  The main thing is to use it
well."
 						-- Rene Descartes
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Mark J. Bobak
  INET: mark_at_bobak.net

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Sun Oct 27 2002 - 22:48:37 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US