LinuxQuestions.org
Help answer threads with 0 replies.
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 10-27-2013, 01:52 PM   #1
123raajesh
LQ Newbie
 
Registered: Sep 2013
Posts: 12

Rep: Reputation: Disabled
Flow control based on grep match pattern or string


Hi,

Looking to create a flow control based on a string or pattern matched in a log file.

The log file may contain either of these 3.

1 CONFSUCCESS
2 CONFFAIL
3 CONFPARTIAL

Example:
cat System.log

dsfasdfasfas
adfsfasfa
safafaf sdfaasfsa CONFSUCCESS
adsfasdfadsfadsf fafasfasdfasdf fafasfafsa
sadfafasfasdfadss fdsafadff fasfadfaf asff

So idea is to grep the message from log, based on pattern run a flow control as below.

if

1 Look in System.log - CONFSUCCESS - show message as - SUCCESSFUL - Ask user to - Press ENTER to continue

if

2 Look in System.log - CONFFAIL - show message as - FAILURE - Exit (come out of shell)

if

3 Look in System.log - CONFPARTIAL - Show message as - PARTIALSUCCESS - Exit (come out of shell)
 
Old 10-27-2013, 02:01 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,717

Rep: Reputation: 4136Reputation: 4136Reputation: 4136Reputation: 4136Reputation: 4136Reputation: 4136Reputation: 4136Reputation: 4136Reputation: 4136Reputation: 4136Reputation: 4136
Quote:
Originally Posted by 123raajesh View Post
Hi,
Looking to create a flow control based on a string or pattern matched in a log file. The log file may contain either of these 3.

1 CONFSUCCESS
2 CONFFAIL
3 CONFPARTIAL

Example:
cat System.log

dsfasdfasfas
adfsfasfa
safafaf sdfaasfsa CONFSUCCESS
adsfasdfadsfadsf fafasfasdfasdf fafasfafsa
sadfafasfasdfadss fdsafadff fasfadfaf asff

So idea is to grep the message from log, based on pattern run a flow control as below.

if 1 Look in System.log - CONFSUCCESS - show message as - SUCCESSFUL - Ask user to - Press ENTER to continue
if 2 Look in System.log - CONFFAIL - show message as - FAILURE - Exit (come out of shell)
if 3 Look in System.log - CONFPARTIAL - Show message as - PARTIALSUCCESS - Exit (come out of shell)
..which is nearly identical to your OTHER thread:
http://www.linuxquestions.org/questi...es-4175482199/

Since you want a shell script/command to do something, please post what YOU have written/tried so far.
 
Old 10-30-2013, 06:40 AM   #3
123raajesh
LQ Newbie
 
Registered: Sep 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
re; Flow control based on grep match pattern or string

I got the solution.

Code:
# Test
if grep -os CONFSUCCESS System.log; then
  echo SUCCESSFUL
elif grep -os CONFFAIL System.log; then
  echo FAILED
elif grep -os CONFPARTIAL System.log; then
  echo "PARTIAL SUCCESS"
fi
Code:
if grep -os A /tmp/1 >> /tmp/log; then   echo "A is mounted"|tee -a /tmp/log else echo "A could not be mounted"|tee -a /tmp/log
fi
if grep -os C /tmp/1 >> /tmp/log; then   echo "c is mounted"|tee -a /tmp/log else echo "C could not be mounted"|tee -a /tmp/log
fi
if grep -os E /tmp/1 >> /tmp/log; then   echo "E is mounted"|tee -a /tmp/log else echo "E could not be mounted"|tee -a /tmp/log
fi
if grep -os G /tmp/1 >> /tmp/log; then   echo "G is mounted"|tee -a /tmp/log else echo "G could not be mounted"|tee -a /tmp/log
fi

Last edited by 123raajesh; 11-10-2013 at 10:25 AM. Reason: updated as code
 
  


Reply

Tags
control, grep


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
How to match for a pattern in a string using tcl kamesp Linux - Software 1 06-08-2012 04:58 PM
[SOLVED] file Renaming based on a pattern match Guyverix Programming 6 01-10-2011 04:40 PM
how to match the exact pattern using grep utility vinaytp Linux - Newbie 3 05-11-2009 12:36 AM
how to match for multiple pattern at the end of given string Santoshkb Programming 2 06-23-2008 10:42 AM
how to grep only one string pr match gummimann Linux - General 3 11-06-2003 09:40 AM


All times are GMT -5. The time now is 06:00 AM.

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