LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Log parse script (https://www.linuxquestions.org/questions/programming-9/log-parse-script-4175571727/)

pavan27 02-08-2016 01:13 PM

Log parse script
 
Hello Experts,
i am trying to write script to monitor replication, fir this i need to read the replication log file and report if my condition is matched. i have below file
Code:

stream id: 8ad5917c1992e82b0c5a9577124603ab/beer-sample/beer-sample
  status: running
  source: beer-sample
  target: /remoteClusters/8ad5917c1992e82b0c5a9577124603ab/buckets/beer-sample
stream id: 8ad5917c1992e82b0c5a9577124603ab/beer-sample/beer-sample1
  status: aborted  >>>>>>>>
  source: beer-sample
  target: /remoteClusters/8ad5917c1992e82b0c5a9577124603ab/buckets/beer-sample1

from the above file, i have two replication streams, one stream is going good another stream is aborted.
my requirement is to read stream id and its status (below line) and report only failed portion (3 lines below stream id (status, source, target).
could you please help me to solve this puzzle.

Thank you,

rtmistler 02-08-2016 01:17 PM

Please review the following link Welcome to LQ

Please realize that the intention of LQ is that you learn how to help yourself.

Check some of the links in my signature which refer to BASH scripting.

Attempt to write a BASH script of your own, or some other means to try to resolve your problem.

Post what you've tried. You say you're trying to write a script, then please post what you have thus far.

Note that people do not know your level of expertise if you don't at least show what you've tried to resolve this problem on your own.

If you've tried nothing except asking a question, then a suggestion is to at least perform a web search to find a potential answer for your question.

TB0ne 02-08-2016 01:19 PM

Quote:

Originally Posted by pavan27 (Post 5497148)
Hello Experts,
i am trying to write script to monitor replication, fir this i need to read the replication log file and report if my condition is matched. i have below file
Code:

stream id: 8ad5917c1992e82b0c5a9577124603ab/beer-sample/beer-sample
  status: running
  source: beer-sample
  target: /remoteClusters/8ad5917c1992e82b0c5a9577124603ab/buckets/beer-sample
stream id: 8ad5917c1992e82b0c5a9577124603ab/beer-sample/beer-sample1
  status: aborted  >>>>>>>>
  source: beer-sample
  target: /remoteClusters/8ad5917c1992e82b0c5a9577124603ab/buckets/beer-sample1

from the above file, i have two replication streams, one stream is going good another stream is aborted. my requirement is to read stream id and its status (below line) and report only failed portion (3 lines below stream id (status, source, target).
could you please help me to solve this puzzle.

You've asked similar questions in the past. And since you say you're trying to write a script, why don't you POST that script?? We are not going to write it for you, but will be happy to help. Read the "Question Guidelines" link in my posting signature. You've been a member here for NINE YEARS now.

Habitual 02-08-2016 01:56 PM

Quote:

Originally Posted by pavan27 (Post 5497148)
Hello Experts,
i am trying to write script to monitor replication

What have you read?
Where did you read it?
What have you tried?
Show us your work.

pavan27 02-08-2016 04:14 PM

Hello Experts,

Thank you so much for reply. i have completed my script.

Quote:

ChkRepl

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~#
# Check Couchbase status #
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~#
ChkRepl () {

$CB_HOME/bin/couchbase-cli xdcr-replicate -c ${HN}:8091 --list >${LOG}

}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~#
# let check the status #
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~#

setup_environment
ChkRepl

STATUS=`grep -iw 'paused' ${LOG}`
if [ $? -eq 0 ]; then
MESSAGE="${HN}:${CB_ENV}: Coubhcase replicaton is had issue "
grep -A2 'paused' ${LOG}|mailx -s "${MESSAGE}" ${CB_EDBA}
fi
exit;




rtmistler 02-08-2016 04:27 PM

Does the script do what you wished it to do? If so, then it's good that you posted it and then also please mark the thread as solved. If there are problems, then it might be helpful to describe those problems.

grail 02-09-2016 06:16 AM

I realise you have only shown a snippet of your script, but am curious how the first line shown would execute correctly if the definition is coming after it is called? Unless of course you have
multiple definitions of the same function?? (if so this could cause a headache in the future)


All times are GMT -5. The time now is 11:23 AM.