If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Help required on "grep"

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-25-03, 17:19
grbabu1 grbabu1 is offline
Registered User
 
Join Date: Mar 2003
Posts: 4
Post Help required on "grep"

I am new to shell scripting. My question is

How to grep exact pattern from a variable in UNIX.

This is the scenario.

In the present server there are 3 oracle databases up and running, which are HRM83DEV, HRM83TST, HRM83CFG. There is no database/s called HRM83LOG, HRM.

This is what I wrote in the shell script

=======================

# script name shtest

if [ X$1 != X ]; then
DBNAME=$1
export DBNAME
else
echo "Database name must be specified as a parameter"
exit
fi

ECH=`ps -fu oracle | grep $DBNAME |grep -c ora_`
if [ "$ECH" = "0" ]; then
echo "The database is not UP and RUNNING, not able to perform backup"
exit
fi

======================

When I Run the script

1. shtest HRM83DEV
(no output, whcih is fine because I did not give any dispaly message)

2. shtest HRM83LOG
The database is not UP and RUNNING, not able to perform backup

3. shtest HRM
(no output like 1st run)

in the 3rd run I am getting nothing. I would like to get as like 2nd run
"The database is not UP and RUNNING, not able to perform backup".

I understand
ps -fu oracle | grep $DBNAME |grep -c ora_ will search the patter starts with H and on.....

I appreciate if anybody help me on this to grep exact pattern search.

Thank you,
Reply With Quote
  #2 (permalink)  
Old 03-27-03, 11:36
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,543
Re: Help required on "grep"

Can you tell what is meant by "exact pattern search" ...

Sorry ...

Cheers

Sathyaram


Quote:
Originally posted by grbabu1
I am new to shell scripting. My question is

How to grep exact pattern from a variable in UNIX.

This is the scenario.

In the present server there are 3 oracle databases up and running, which are HRM83DEV, HRM83TST, HRM83CFG. There is no database/s called HRM83LOG, HRM.

This is what I wrote in the shell script

=======================

# script name shtest

if [ X$1 != X ]; then
DBNAME=$1
export DBNAME
else
echo "Database name must be specified as a parameter"
exit
fi

ECH=`ps -fu oracle | grep $DBNAME |grep -c ora_`
if [ "$ECH" = "0" ]; then
echo "The database is not UP and RUNNING, not able to perform backup"
exit
fi

======================

When I Run the script

1. shtest HRM83DEV
(no output, whcih is fine because I did not give any dispaly message)

2. shtest HRM83LOG
The database is not UP and RUNNING, not able to perform backup

3. shtest HRM
(no output like 1st run)

in the 3rd run I am getting nothing. I would like to get as like 2nd run
"The database is not UP and RUNNING, not able to perform backup".

I understand
ps -fu oracle | grep $DBNAME |grep -c ora_ will search the patter starts with H and on.....

I appreciate if anybody help me on this to grep exact pattern search.

Thank you,
Reply With Quote
  #3 (permalink)  
Old 03-28-03, 12:06
grbabu1 grbabu1 is offline
Registered User
 
Join Date: Mar 2003
Posts: 4
Post

Sathyaram,

Example:

If I give

ps -fu oracle |grep HRM

Here I mean HRM is the exact pattern search

it is giving process in oracle all start with HRM, also HRM83, HRM83TST and so on...but what I need is only HRM not HRM83 or HRM83TST....

Thank you,
Reply With Quote
  #4 (permalink)  
Old 03-28-03, 13:19
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,543
grep is designed so ...

Assuming HRM to be a word in the output, you can use

ps -fu oracle | grep " HRM "

ie, a blank on either side of HRM ...

or, if you will have HRM as the first word in a sentence also , then

egrep "HRM | HRM "

Hope this helps

Cheers

Sathyaram

Quote:
Originally posted by grbabu1
Sathyaram,

Example:

If I give

ps -fu oracle |grep HRM

Here I mean HRM is the exact pattern search

it is giving process in oracle all start with HRM, also HRM83, HRM83TST and so on...but what I need is only HRM not HRM83 or HRM83TST....

Thank you,
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On