After 15 mins i need to check the log from 4:00 PM to 4:15 PM.
Need to check logs file for 2 strings (a) Feed id=200 (b) Item=Product example, if these 2 string matches i need to check for "Error" string.
If 3 string matches i will send a mail stating "Failed"
If string "Error" is not found in last 15 mins log(only string a & b should match) then i will execute another 6 URLS and atlast will trigger mail stating "Success"
Is this above sequence possible in shell script? Please guide me and my script is below - Im really stuck in comparing string and checking last 15 mins log.
Log with Error
[INFO 12-03-01:04:10:25] Starting FeedRunner for feed: 200 Product example Items
[INFO 12-03-01:04:12:40] Error FeedRunner for feed: 200 Product example Items
[INFO 12-03-01:04:20:25] Stopping FeedRunner for feed : 200 Product example Items Feed time taken 231743
Log without Error
[INFO 12-03-01:04:10:25] Starting FeedRunner for feed: 200 Product example Items
[INFO 12-03-01:04:20:25] Stopping FeedRunner for feed : 200 Product example Items Feed time taken 2743
I don't think there's any point making 'start' and 'end' dates like you have there. It'll only take a fraction of a second to get the feed, and those dates aren't useful in comparing anything in the log file.
What's your system? What's your shell? On Linux, GNU awk has features allowing you to get epoch time from timestamps, which is very handy for comparing how long ago things happened...
Please tell us more about the logfile /path/logfile.log .
Does the program append to the log every time it is run or is the log created from scratch?
If the log is appended you could consider adding your own entries to the log containing the values of your $START and $END variables such that you can find them with "sed".
Please reply to the above request: What Operating System and version do you have and what Shell are you using?
There are multiple logic and syntax errors in your most recent script.
This was not an off-hand question. Different systems have very different ways of working with dates. Any answer I give you right now has good odds of being useless to you, since it's for the wrong system.
Best approach is to make your own entries to the log from shell. One before the run and one after the run. Stick to the syntax of the logfile itself for the left hand side of the logfile entry, but include your own unique start and end string to your special lines in order to make it possible to use your original "sed" syntax.
I would put your unique search string in the text portion of the message and use only alphanumeric characters. You just need to include the date but in numeric yyyymmddhhmmss format and something to distinguish start from end.
For example
[INFO 12-03-01:04:10:24] S20120301041024
[INFO 12-03-01:04:10:25] Starting FeedRunner for feed: 200 Product example Items
[INFO 12-03-01:04:12:40] Error FeedRunner for feed: 200 Product example Items
[INFO 12-03-01:04:20:25] Stopping FeedRunner for feed : 200 Product example Items Feed time taken 231743
[INFO 12-03-01:04:10:26] E20120301041026