A message for Linux.com registered users: We are in the process of making changes to the Linux forums. Starting Monday, 8/13/18 at 6:00 PM PT, you will be unable to access the forums. They will re-launch as soon as possible on Wednesday, 8/15/18 with new features and improved functionality. Thank you for your patience and stay tuned for the new improved forums.

October 27, 2013

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

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)

Thanks

Click Here!