LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 08-25-2014, 07:52 AM   #1
TheBest43
LQ Newbie
 
Registered: Aug 2014
Posts: 5

Rep: Reputation: Disabled
Question Check START and END strings on the last minute comparing with current time


I have a log file.

This log file has following format.

Log file is placed on dynamic a path, so first I need to find most recent log file on some folder and after that I need to know if there is a START and END string on the last log file that is being written on the last minute related to last record of that log file.

Path

# path/to/folder/YYYY/MM/DD

Log File

2014-08-25T08:25:35+02:00 START, user: abc1
2014-08-25T08:25:35+02:00 Doing 1, user: abc1
2014-08-25T08:25:35+02:00 Doing 2, user: abc1
2014-08-25T08:25:35+02:00 END, user: abc1

Strings to be checked in 1 minute comparing with current time.
START and END

Thanks in advanced.
 
Old 08-25-2014, 08:04 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
What have you done to accomplish this task, so far?
 
Old 08-25-2014, 08:08 AM   #3
TheBest43
LQ Newbie
 
Registered: Aug 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
Question

Haven't started yet. I shouldn't use tail since it always should be there waiting for the log to be written but first I need to solve how find for the last log file inside that folder.
 
Old 08-25-2014, 08:36 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Here's a blog regarding BASH scripting; there are other languages for scripting, but I lean towards BASH myself. There are also various guides about BASH scripting just by searching the web.

The main point about BASH scripting which I emphasize is that "anything which you can do on a command line, you can script", which is to say that in order to accomplish your intended goal, your first actions are "typing commands manually and observing the outcome".

Therefore you can see what files are newest, by sorting by date, and see whether or not a file meets your START/END criteria, by visual inspection.

For a script you can also list files by date, and then look at the newest log file and search for both text terms and get a result.

A suggestion is to attempt to write a script where you first find the file you should be checking and then figure out how to search the file for both words, for example two different grep commands much like you would do from the command line. I don't believe you stated what you intend to do beyond the point of discovery that a log is complete, but at that point you can perform other intended actions.

My simplest actions here would be to perform an 'ls -lrt' or some other form of ls to find the most recently created/modified log file. I would save that file name as a variable in my script and I would then search that file; using grep for the string START and the string END, if both of those tests succeeded, then that would tell me that my found file was one that I wanted. I would probably do this for all files anyways and turn on debug or echo my results to a log file so that I could understand how my script really worked, before I then limited it to operate as I intended.
 
Old 08-25-2014, 08:42 AM   #5
TheBest43
LQ Newbie
 
Registered: Aug 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
Exclamation

Quote:
Originally Posted by rtmistler View Post
Here's a blog regarding BASH scripting; there are other languages for scripting, but I lean towards BASH myself. There are also various guides about BASH scripting just by searching the web.

The main point about BASH scripting which I emphasize is that "anything which you can do on a command line, you can script", which is to say that in order to accomplish your intended goal, your first actions are "typing commands manually and observing the outcome".

Therefore you can see what files are newest, by sorting by date, and see whether or not a file meets your START/END criteria, by visual inspection.

For a script you can also list files by date, and then look at the newest log file and search for both text terms and get a result.

A suggestion is to attempt to write a script where you first find the file you should be checking and then figure out how to search the file for both words, for example two different grep commands much like you would do from the command line. I don't believe you stated what you intend to do beyond the point of discovery that a log is complete, but at that point you can perform other intended actions.

My simplest actions here would be to perform an 'ls -lrt' or some other form of ls to find the most recently created/modified log file. I would save that file name as a variable in my script and I would then search that file; using grep for the string START and the string END, if both of those tests succeeded, then that would tell me that my found file was one that I wanted. I would probably do this for all files anyways and turn on debug or echo my results to a log file so that I could understand how my script really worked, before I then limited it to operate as I intended.
Thanks for your time to answer rtmistler, but is it possible to go to the practice? Besides, you don't mention about how you would treat the time if it's needed to know if the log got the START and END strings in the last minute. If you doesnt mind, could you please help me building this script in bash?

I will appreciate it.

Thanks in advanced.

Last edited by TheBest43; 08-25-2014 at 08:45 AM.
 
Old 08-25-2014, 08:52 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I think you need to be more clear about what your intended actions need to be. Please do not merely reiterate your first post, because that's already visible. You have log files, you need to determine which is the newest log file and you need to determine that the most recent log file contains both START and END records. It seems as if you wish to check these once per minute to see if changes meet your criteria. That's about all I can determine. Perhaps what you're saying is that you need to check a log file once per minute to determine that the END log record has been added, or perhaps you need to determine cases where the START and END log entries are greater than one minute apart, because the example you've shown illustrates all entries are at the same time versus separated in time. I don't know the full requirements.

I'd say start by writing out the command prompt actions which you do to determine what you need to determine. Once you know those, you can write a script and further vary things to automate your actions.
 
  


Reply



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
[SOLVED] Bash Comparing similar strings pople Programming 3 03-10-2014 10:07 PM
[SOLVED] Search for 2 strings between a start and end range in awk dazdaz Programming 2 03-15-2013 08:53 AM
[SOLVED] [makefile] Add start/end time? littlebigman Linux - Software 3 05-23-2011 10:10 AM
Comparing strings in linux raviraj2018 Linux - Software 3 07-30-2009 03:04 AM
c++ - if/else problem comparing strings babag Programming 14 05-19-2008 11:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:23 PM.

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
Open Source Consulting | Domain Registration