Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2003
    Posts
    4

    Post Unanswered: 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,

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: Help required on "grep"

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

    Sorry ...

    Cheers

    Sathyaram


    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,

  3. #3
    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,

  4. #4
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    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

    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,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •