[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Very simple bash question

Posted on 2004-08-16
4
Medium Priority
?
322 Views
Last Modified: 2010-04-21
This has to be an easy question, I am currently brain-fried from doing other bash scripting...

I have a file that logs timestamps every 20 minutes...
I an error occurs on the system it is logged in this file...
Example:
2004-08-14 22:38:25: ------ TimeCheck - Sat Aug 14 22:40:00 2004
2004-08-14 22:58:25: ------ TimeCheck - Sat Aug 14 23:00:00 2004
2004-08-14 23:18:24: ------ TimeCheck - Sat Aug 14 23:20:00 2004
2004-08-14 23:25:09: ERROR Message goes here
2004-08-14 23:25:10: Additional error info here
2004-08-14 23:25:12: and here
2004-08-14 23:25:12: and here
2004-08-14 23:25:12: and here

etc.. etc...
I need, in my script to be able to cat this file, find the last TimeCheck, report the last TimeCheck, then print out the next 15 lines or so...

I don't mind using awk or sed or anything!!! Just has to be in a bash script...
I could work on this for another hour or so, but I need some sleep..

Thanks in advance.
0
Comment
Question by:g8ballz0fyre
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Expert Comment

by:cjjclifford
ID: 11808191

#!/bin/bash

# error checking needs completion!
filename=$1

awk '/TimeCheck/{i=0;trc=1}{ if( trc == 1 && i != 16 ){ last_15[i++] = $0}}}END{for( j = 0; j != i; j++){ print last_15[j]}}' $filename
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 200 total points
ID: 11808194
Hi g8ballz0fyre,

tac logfile |  grep "time stamp"  -B 15 -m 1

Sunnycoder
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 11808196
Sorry, too many brackets in the awk program - here's the correct one...

awk '/TimeCheck/{i=0;trc=1}{ if( trc == 1 && i != 16 ){ last_15[i++] = $0}}END{for( j = 0; j != i; j++){ print last_15[j]}}'
0
 
LVL 11

Expert Comment

by:lbertacco
ID: 11808263
Sunnycoder, I'd pipe the output to tac again to get lines the original order:

tac logfile |  grep "TimeCheck"  -B 15 -m 1 | tac
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question