LinuxQuestions.org
Visit Jeremy's Blog.
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 06-06-2012, 07:03 PM   #1
blsimpson
LQ Newbie
 
Registered: Jun 2012
Posts: 15

Rep: Reputation: Disabled
A little scripting help..


Hello all, been gathering a lot of info from here for the past couple of years, its been very invaluable.

My problem. We have an application that generates log files, on multiple machines, that I need to monitor on a daily basis. These machines also do not have access to the internet, so no email. The log files roll over to new ones when they reach a certain size, and have a time stamp of when they were created, but will have multiple days inside it. I need to monitor the last 24 hours for certain strings (ERROR and Exception). I figured out how multiple ways to pull these out and place them into another file, but I am having a problem just getting the last 24 hours.. Here is what I am using, which was taken from the internet from a couple different places and modified to fit what I need.


Code:
#!/bin/bash

#if there's no 'log' file
if [ ! -e "log-`date '+%Y-%m-%d'`.log" ] ; then
# let's search for the word 'ERROR' in our log and save the output to the newly created file named 'log' with a date stamp.
  grep ERROR sanjay.log > "log-`date '+%Y-%m-%d'`.log"
# if however the 'logs' file already exists..
else
# update our log*
  grep ERROR sanjay.log >> "log-`date '+%Y-%m-%d'`.log"
fi
Feel free to tell me I am doing it completely wrong Some examples of what the log looks like:

Code:
2012-06-06 17:30:04,675 INFO [org.springframework.integration.handler.LoggingHandler] - <JobExecution: id=15137, startTime=Wed Jun 06 17:30:04 EDT 2012, endTime=Wed Jun 06 17:30:04 EDT 2012, lastUpdated=Wed Jun 06 17:30:04 EDT 2012, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=14931, JobParameters=[{INPUT_FILE_NAME=REVERSE_DRAFT5_FILE_2012-06-06-17-30-00, input.file.name=REVERSE_DRAFT5_FILE_2012-06-06-17-30-00}], Job=[reverseDraft5MessageProcessingJob]]>
job-requests
2012-06-06 17:30:04,675 INFO [com.xxxxxxx.xxxxxxx.batch.ap.draft5.ReverseDraft5JobProcessor] - <End of Reverse Draft5 Job at:2012-06-06-17-30-04>
 
Old 06-06-2012, 07:13 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Seeing as you are familiar with the data cmd, use that to generate yesterday's date in the matching format to the log file, and then grep that eg (simple example)
Code:
x@x> cat t.t
hostname1 17/08/10
hostname1 18/08/10
hostname1 19/08/10
hostname1 20/08/10
hostname2 17/08/10
hostname2 18/08/10
hostname2 19/08/10
hostname2 20/08/10

x@x> d=17/08/10
x@x> echo $d
17/08/10

x@x> grep $d t.t
hostname1 17/08/10
hostname2 17/08/10
should give you the idea.
You may find these useful
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 06-07-2012, 01:11 PM   #3
blsimpson
LQ Newbie
 
Registered: Jun 2012
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by chrism01 View Post
Seeing as you are familiar with the data cmd, use that to generate yesterday's date in the matching format to the log file, and then grep that eg (simple example)
Code:
x@x> cat t.t
hostname1 17/08/10
hostname1 18/08/10
hostname1 19/08/10
hostname1 20/08/10
hostname2 17/08/10
hostname2 18/08/10
hostname2 19/08/10
hostname2 20/08/10

x@x> d=17/08/10
x@x> echo $d
17/08/10

x@x> grep $d t.t
hostname1 17/08/10
hostname2 17/08/10
should give you the idea.
You may find these useful
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
I am not sure I understand the first part of your post at all. Thanks for the links though, I will give those a read.

Anyone else have some insight?
 
  


Reply


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
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 05:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 11:09 PM
need help in scripting..... raghuvamsi Programming 2 06-27-2008 05:59 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
another help with scripting?! ice99 Programming 2 08-09-2005 09:56 AM


All times are GMT -5. The time now is 10:58 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