LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-15-2013, 01:27 PM   #16
rraina
LQ Newbie
 
Registered: Mar 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled

Dear TBOne, Thanks for your rude attempts to help.I already tried what you suggested and that solves one purpose. If I already knew everything I would not have been asking questions here.Reading tutorials is one thing but how to implement in a script is another.

Shivaa, I have already explained the scenario as below:


I have various domain names(DN) like app_dev, ws_prd, wcc, app_prd where the letters after the underscore denotes the environment(i.e. env), when it doesnt have an undersore, its the per environment.
That is what I want to do as I have outlined in the code below.I want the script to check explicitly for the underscore, if its there in the DN value then the value of environment will set equal to the letters after the underscore.If the underscore is not there, it does the nslookup for the VIP which has the environment name suffixed to it and assign the value to env. Earlier I had though of doing nsloopkup for all cases, but that would not be a good idea to have so many nslookups.
For the DN value, the number of letters before and after the underscore should be variable.


I am trying my best to explain everything well and seek help and not here to offend anyone.
 
Old 03-15-2013, 02:11 PM   #17
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
...If the underscore is not there, it does the nslookup for the VIP which has the environment name suffixed to it and assign the value to env.
Please explain it little more. Can you give some example of this with desired output, if no underscore character there in DN? Also let's know what's VIP?

Well, TBOne is an experienced guy, and has just pointed what best suits for you. He just wants you to learn from such problems, so in case of need you can use such sort of scripting approches in future.
 
Old 03-15-2013, 02:14 PM   #18
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,954

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by rraina View Post
Dear TBOne, Thanks for your rude attempts to help.I already tried what you suggested and that solves one purpose. If I already knew everything I would not have been asking questions here.Reading tutorials is one thing but how to implement in a script is another.
First, you never acknowledged you read or tried it. Second, I believe that (since I gave you the solution), a "thanks" would be in order, rather than sarcasm about "rude attempts to help". I didn't "attempt" to help...I DID, by giving you the solution.

Also, if you looked at any of the tutorials, they have EXAMPLES, which would be sample code that would get you going. Unless you read and try to follow the examples, you won't EVER learn how to do it yourself. Again, posting your script (rather than just repeating the question), and telling us where you're stuck would let folks give you help.
Quote:
I have various domain names(DN) like app_dev, ws_prd, wcc, app_prd where the letters after the underscore denotes the environment(i.e. env), when it doesnt have an undersore, its the per environment.
That is what I want to do as I have outlined in the code below.I want the script to check explicitly for the underscore, if its there in the DN value then the value of environment will set equal to the letters after the underscore.If the underscore is not there, it does the nslookup for the VIP which has the environment name suffixed to it and assign the value to env. Earlier I had though of doing nsloopkup for all cases, but that would not be a good idea to have so many nslookups.
For the DN value, the number of letters before and after the underscore should be variable.

I am trying my best to explain everything well and seek help and not here to offend anyone.
Except me, I'm guessing.

Since I gave you a 'rude' solution to the first part of your problem, and since you seem unwilling/unable to look it up or apply what others have told you, I'll give you second part, too.
Code:
if [[ "$DN" == *_* ]]
then
  echo "The underscore is present";
  env=`echo $DN | cut -d '_' -f 2 `
fi
You STILL haven't posted any of your code, despite repeated requests. You were pointed to tutorials, which have examples on how to do EVERYTHING you're asking, but haven't read them. Even after that, I handed you the answer, and you're nasty about it. Feel free to complain and be rude about me spoon-feeding you the rest of your answer, and saving you the trouble of looking anything up or learning on your own.
 
Old 03-15-2013, 02:33 PM   #19
rraina
LQ Newbie
 
Registered: Mar 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
The VIP is "appadmper".

Below the "else" statement of this script which shows how the nslookup will work when there is no underscore in the value of $DN(this is working perfectly as expected):

Code:
elseif [ `nslookup appadmper|grep Name | awk {'print $2'} | cut -c-6` == `hostname` ] ; then env="per";
 
Old 03-15-2013, 02:38 PM   #20
rraina
LQ Newbie
 
Registered: Mar 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
The first script start_admin.sh is as below.This will call wa_common.sh.
Sharing the wa_common.sh script in the next post:


Code:
#!/bin/bash
. ~/.bash_profile

source $ADMIN_BASE/scripts/wa_common.sh
if [ $? -ne 0 ]; then
   echo "ERROR: unable to find shared function library wa_common.sh."
   exit 1
fi

setworkdir

DOMAIN_NAME=`basename $WORKDIR`
if [ $DOMAIN_NAME == "domains" ]; then
   echo "ERROR: this script must be run from the ADMIN_HOME of a domain."
   exit 1
fi

. oraenv.sh d $DOMAIN_NAME
if [ $? -eq 0 ]; then
   adminservercheck $DOMAIN_NAME `hostname`
   if [ $? -ne 0 ]; then
      echo "ERROR: this script must be run from an admin server host."
      exit 1
   fi

   mkdir -p $WORKDIR/logs 2>/dev/null
   MAIN_LOG=$WORKDIR/logs/`basename $0 | sed 's/\.sh/\.out/g'`
   rotatelog $MAIN_LOG 524288
   echo "###################################################################################################" >> $MAIN_LOG
   date >> $MAIN_LOG

   nc -z localhost 5556 &>/dev/null
   if [ $? -ne 0 ]; then
      echo "NOTICE: node manager does not seem to be running. Attempting to start..." | tee -a $MAIN_LOG
      start_nm.sh &>/dev/null

      if [ $? -ne 0 ]; then
         echo "ERROR: error(s) starting node manager." | tee -a $MAIN_LOG
         exit 1
      else
         echo "Node manager started successfully." | tee -a $MAIN_LOG
      fi
   fi

   if [ -f $ADMIN_BASE/keystore/Trust.jks ]; then
      java -Dweblogic.security.SSL.trustedCAKeyStore=$ADMIN_BASE/keystore/Trust.jks weblogic.WLST $WORKDIR/../start_admin.py 2>&1 | tee -a $MAIN_LOG
   else
      java weblogic.WLST $WORKDIR/../start_admin.py 2>&1 | tee -a $MAIN_LOG
   fi

   if [ ${PIPESTATUS[0]} -ne 0 ]; then
      echo -e "\nERROR: error(s) starting the admin server." | tee -a $MAIN_LOG
      exit 1
   else
      echo -e "\nAdmin server started successfully." | tee -a $MAIN_LOG
   fi
else
   echo "ERROR: failed to switch to domain ${DOMAIN_NAME}."
 
Old 03-15-2013, 02:42 PM   #21
rraina
LQ Newbie
 
Registered: Mar 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
below is the wa_common.sh script. I have to tweak the adminservercheck function from the part where the env value is set.

Code:
adminservercheck() {
   local ENV=""
   local DOMAIN=""
   local DOMAIN_NAME=$1
   local HOST=`echo $2 | tr '[A-Z]' '[a-z]'`

   if [[ `expr match "$DOMAIN_NAME" 'ALM_'` -gt 0 ]]; then DOMAIN="alm"
   elif [[ `expr match "$DOMAIN_NAME" 'APP_'` -gt 0 ]]; then DOMAIN="app"
   elif [[ `expr match "$DOMAIN_NAME" 'BI_'` -gt 0 ]]; then DOMAIN="bi"
   elif [[ `expr match "$DOMAIN_NAME" 'BIO_'` -gt 0 ]]; then DOMAIN="bio"
   elif [[ `expr match "$DOMAIN_NAME" 'IDM_'` -gt 0 ]]; then DOMAIN="idm"
   elif [[ `expr match "$DOMAIN_NAME" 'UCM_'` -gt 0 ]]; then DOMAIN="ucm"
   elif [[ `expr match "$DOMAIN_NAME" 'WCC_'` -gt 0 ]]; then DOMAIN="wcc"
   elif [[ `expr match "$DOMAIN_NAME" 'WS_'` -gt 0 ]]; then DOMAIN="ws"
   else
      echo "ERROR: unsupported domain type in $DOMAIN_NAME."
      exit 1
   fi

   if [[ x`expr match "$DOMAIN_NAME" '.*\(_SB$\)'` == "x_SB" ]]; then ENV="sb"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_AT$\)'` == "x_AT" ]]; then ENV="at"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_BPV$\)'` == "x_BPV" ]]; then ENV="bpv"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_DEV$\)'` == "x_DEV" ]]; then ENV="dev"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_DEVA$\)'` == "x_DEVA" ]]; then ENV="deva"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_DEVS$\)'` == "x_DEVS" ]]; then ENV="devs"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_DEVI$\)'` == "x_DEVI" ]]; then ENV="devi"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_DEVU$\)'` == "x_DEVU" ]]; then ENV="devu"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_PER$\)'` == "x_PER" ]]; then ENV="per"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_SYS$\)'` == "x_SYS" ]]; then ENV="sys"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_SYSS$\)'` == "x_SYSS" ]]; then ENV="syss"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_UAT$\)'` == "x_UAT" ]]; then ENV="uat"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_UATS$\)'` == "x_UATS" ]]; then ENV="uats"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_QAT$\)'` == "x_QAT" ]]; then ENV="qat"
   elif [[ x`expr match "$DOMAIN_NAME" '.*\(_PRD$\)'` == "x_PRD" ]]; then ENV=""
   else
      echo "ERROR: unsupported domain environment in $DOMAIN_NAME."
      exit 1
   fi

   local ADMHOST=`nslookup ${DOMAIN}adm${ENV} | grep Name | awk {'print $2'} | cut -c-6`

   if [ $HOST == $ADMHOST ]; then
      return 0
   fi

   return 1
}

debug() {
   echo "DEBUG: $*" >&2;
}

rotatelog() {
   local LOGFILE=$1
   local LOGSIZE=$2

   if [[ -f $LOGFILE && `stat -c%s $LOGFILE` -gt $LOGSIZE ]]; then
      mv $LOGFILE ${LOGFILE}.prev
      touch $LOGFILE
   fi
}

setworkdir() {
   DIRCHECK=`dirname $0 | cut -c1`
   if [ $DIRCHECK == "." ]; then
      WORKDIR=$PWD
   elif [ $DIRCHECK == "/" ]; then
      WORKDIR=`dirname $0`
    fi
}

# Wait for children to exit and indicate their exit status
waitall() {
   errors=0
   while :; do
      #echo
      #debug "Processes remaining: $*"
      for pid in "$@"; do
         shift
         if kill -0 "$pid" 2>/dev/null; then
            #debug "$pid is still alive."
            set -- "$@" "$pid"
         elif wait "$pid"; then
            #debug "$pid exited with zero exit status."
            :
         else
            #debug "$pid exited with non-zero exit status."
            ((++errors))
         fi
      done

      (("$#" > 0)) || break
      sleep ${WAITALL_DELAY:-1}
   done
   ((errors == 0))
}
Hope it helps you all now.
 
Old 03-15-2013, 04:44 PM   #22
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,954

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by rraina View Post
below is the wa_common.sh script. I have to tweak the adminservercheck function from the part where the env value is set.

Code:

Hope it helps you all now.
Great...but have you tried any of the suggestions given to you, or made any changes yet? What are the results?? From what you've posted, we can't tell if you fixed it, or if it's still not working the way you want.

You said:
Quote:
Originally Posted by rraina
I want the script to check explicitly for the underscore, if its there in the DN value then the value of environment will set equal to the letters after the underscore
...and I gave you exactly what does that in my last reply. Have you tried to implement it? From what you posted, it looks like you are already SETTING the $ENV variable, based on what's in there. Put it in above the nslookup line in your script.
Code:
if [[ "$DOMAIN" == *_* ]]
then
  ENV=`echo $DOMAIN | cut -d '_' -f 2 `
local ADMHOST=`nslookup ${DOMAIN}adm${ENV} | grep Name | awk {'print $2'} | cut -c-6`
fi
Again, you need to modify it to suit you, but based on what you posted, your question doesn't make sense. It would appear that all of the $ENV setting is already done, and if it doesn't match what's already defined, the script dies. The underscores are already in the DOMAIN_NAME variables, and are being removed.
 
Old 03-15-2013, 04:48 PM   #23
rraina
LQ Newbie
 
Registered: Mar 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
I will incorporate the modifications and update here by monday.
 
Old 03-15-2013, 05:23 PM   #24
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,954

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by rraina View Post
I will incorporate the modifications and update here by monday.
Saying "thank you" would be nice too...perhaps even "I'm sorry" for being nasty?
 
Old 03-18-2013, 10:57 AM   #25
rraina
LQ Newbie
 
Registered: Mar 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
It should be you who should be saying sorry, not me. And I thought this forum was meant to learn and help and not ask others for saying thank you or sorry.You should check your own posts for the language you chose to write which is far from being helpful. I am sorry I came to this forum for help.Thanks all for your replies.
 
Old 03-18-2013, 11:11 AM   #26
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by rraina View Post
It should be you who should be saying sorry, not me. And I thought this forum was meant to learn and help and not ask others for saying thank you or sorry.You should check your own posts for the language you chose to write which is far from being helpful. I am sorry I came to this forum for help.Thanks all for your replies.
TB0ne has already expressed sorry (check post#24) for being nasty. And I think nothing was intentional at all, so don't be harsh. We all are volunteer here and we can only try to help you out on basis of what info. you've provided. Incomplete info. may lead to confuse others. However, just be cool and calm.

Have good luck!
 
Old 03-18-2013, 01:51 PM   #27
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,954

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by rraina View Post
It should be you who should be saying sorry, not me. And I thought this forum was meant to learn and help and not ask others for saying thank you or sorry.You should check your own posts for the language you chose to write which is far from being helpful. I am sorry I came to this forum for help.Thanks all for your replies.
Your questions were answered, and you showed no effort on your part, aside from restating the question over and over. I directed you to tutorials (with EXAMPLES), where you could have actually LEARNED how to do it yourself. When that didn't work, I even handed you your answers. Yes, this forum is for helping and learning...you didn't, since you ignored the hints you were given, you didn't answer questions you were asked, and didn't try to look it up (even when you were handed examples). Not much anyone can do to help you when you don't put some effort forward of your own, or even answer questions.

Yet, you still don't say thanks for the help you received from anyone, don't say if the solutions worked, and are still complaining about how people aren't nice enough to you. Too bad...you were rude, didn't answer questions, and yet you STILL got help and solutions. Try posting questions like this on any other forum, and see how they respond there.

Last edited by TB0ne; 03-18-2013 at 01:54 PM.
 
Old 03-18-2013, 03:53 PM   #28
rraina
LQ Newbie
 
Registered: Mar 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
Implemented the below code in my script and it worked as required. Thanks to everybody who helped me.

Code:
 if [[ $DOMAIN_NAME =~ "_PRD\$" ]]; then ENV=""
      elif  [[ $DOMAIN_NAME =~ "^_" ]] ;then env=$(echo $DOMAIN_NAME | cut -d '_' -f 2 )
      elif
         for ENV in per; do
         if [ `nslookup ${DOMAIN}adm${ENV}|grep Name | awk {'print $2'} | cut -c-6` == `hostname` ] ; then env="$ENV";
      else
      echo "ERROR: unsupported domain environment in $DOMAIN_NAME."
      exit 1
      fi
      done
      fi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 10 07-17-2012 10:36 AM
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 1 07-13-2012 02:03 AM
Shell script, Perl script, command or utility to convert Binary to text Perseus Programming 26 07-12-2012 07:00 AM
[SOLVED] bash and xterm: how make apps started by and for a script persist when script terminates porphyry5 Linux - General 4 06-15-2011 02:27 PM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM


All times are GMT -5. The time now is 09:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration