AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
Expand all | Collapse all

need assistance on scripting in AIX

  • 1.  need assistance on scripting in AIX

    Posted Wed November 27, 2013 01:14 AM

    Originally posted by: Vishal_dba


    Hello,

    In a loop I am using below command for every database

    crsctl status res | grep -E "ora\.$DATABASE\.(.+)\.svc" and below is one of the sample output
    NAME=ora.sgraphut.sgraphutxdb.svc

    Now I want to extract just service name out of this string (that is sgraphutxdb) please help me how do I proceed?
    Additionally,if I need to pass the node name as one of the parameters while calling this script
    Let's suppose the script name is test_relocate.sh and I need to execute this like below:
    test_relocate.sh -n node1
    Now how do I use this argument inside the script in a loop



    Best regards,
    Vishal



  • 2.  Re: need assistance on scripting in AIX

    Posted Wed November 27, 2013 05:13 PM

    Originally posted by: talex


    ServiceName=$(echo $NAME | cut  -d '.' -f3)

     



  • 3.  Re: need assistance on scripting in AIX

    Posted Thu November 28, 2013 11:54 AM

    Originally posted by: Wouter Liefting


    If this is inside a tight loop, you may want to avoid calling multiple programs.

    Here's an example of doing the same thing (grep & cut), but with a single call to awk:

    crsctl status res | awk -F . "/ora\.$DATABASE\.(.+)\.svc/"' {print $3}'

    or even better as this only checks the second field, then prints the third field - but I don't know if that's exactly what you want:

    crsctl status res | awk -F . -v db="$DATABASE" '$2 == db {print $3}'

    You should be able to do the same thing with sed and perl too.

     

    For your second question, you can access the positional parameters from within your shell script with $1, $2, ... If it's just one or two parameters that you need, that's enough. If you want to pass a whole bunch of options and parameters, you may want to read up on getopt, and argument parsing using shift.