LinuxQuestions.org
Help answer threads with 0 replies.
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, 08: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, 09:04 AM   #2
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
What have you done to accomplish this task, so far?
 
Old 08-25-2014, 09: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, 09:36 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,087
Blog Entries: 10

Rep: Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521
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, 09: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 09:45 AM.
 
Old 08-25-2014, 09:52 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,087
Blog Entries: 10

Rep: Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521
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


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


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