Script to alert an error

Hi

I am writing a shell script which will grep for a particular string e.g. "Process has not started" which i am able to find using a simple grep command on this file and then sending an email alert every 5 mins. Now problem is this email is coming even after this problem is resolved.
once problem is resolved then a new message comes in file e.g. "Process has started successfully" but there are multiple lines in different format between not working and successful.

What command i can use to check "Process has started successfully" is there after "Process has not started" so to ignore the email alert and assume all fine now. else send the email alert. If success message is before failure message then it is an error and should be alerted.

any suggestion would be appreciated. I am trying in shell script.

Any attempts/ideas/thoughts from your side? Please post your work in progress.

You can use egrep to search the file for both strings and pipe the output through tail to just get the last entry and test against that. something like:

egrep -E "Process has not started|Process has started successfully" | tail -1