LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-17-2018, 11:26 AM   #1
sco1984
Member
 
Registered: Sep 2005
Location: Pune, India
Distribution: openSUSE Leap
Posts: 137

Rep: Reputation: 15
Question How to create script to read time stamps of latest log files


Hello,

I have a scenario where 4 different logs get generated =

i) application1_2018-04-17.log
ii) mobile_57f105fca138a [text after underscore keeps changing]
iii) db_exectime_2018-04-17.log
iv) app_error_2018-04-17.log

Can somebody help me to create a script which will read latest geenrated log files of each of them and print the output?

Thanks & Regards,
Amey.
 
Old 04-17-2018, 11:58 AM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,726

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
I will, for a fee
What do you need help with?
What have you tried?
 
1 members found this post helpful.
Old 04-17-2018, 12:14 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by sco1984 View Post
Hello,
I have a scenario where 4 different logs get generated =

i) application1_2018-04-17.log
ii) mobile_57f105fca138a [text after underscore keeps changing]
iii) db_exectime_2018-04-17.log
iv) app_error_2018-04-17.log

Can somebody help me to create a script which will read latest geenrated log files of each of them and print the output?
You've been here for thirteen years now; you should be well aware that we aren't going to write your scripts for you. Read the "Question Guidelines" link in my posting signature.

If you want this script, post what YOU have written/done/tried so far, and tell us where you're stuck, along with samples of the input data and what you want the desired output data to look like. If you show no effort, you will receive no help.
 
1 members found this post helpful.
Old 04-19-2018, 12:53 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As the others said, show us your code so far..
Also, define 'latest' for the 'mobile_....' one. Is that supposed to be an ever increasing hex num. If not, what constitutes 'latest'?
 
Old 05-01-2018, 09:20 AM   #5
uptouch
LQ Newbie
 
Registered: May 2018
Location: Nashville
Distribution: SunOS
Posts: 2

Rep: Reputation: Disabled
I found a Pearl script that I wrote for my assignment to display Apache log entries in the last 10 minutes (apache_log_filter.pl):
Code:
#!/usr/bin/perl
use POSIX;

# The script prints only records for the last five minutes (300 seconds). The time interval is controlled by the delay parameter (specified in seconds).
my $delay = 300;

my $curtime = time();
my @months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

# In the cycle, time stamps are analyzed and only records that are included in the specified time interval are displayed.
# In the journal entries, the timestamps should be the same time zone where this script will run.
while (defined($line_ = <STDIN>)) {

	# Parsing the time stamp of the journal entry. This section must be edited for each individual log (because the structure of the time stamp record is different).
        $ib = index($line_,"[");
	$ie = index($line_,"]");
	$ds = substr($line_, $ib+1, $ie-$ib-1);

	my $day  = substr($ds, 0, 2);
	my $mon  = substr($ds, 3, 3);
	my $year = substr($ds, 7, 4);
	my $hour = substr($ds, 12, 2);
	my $min  = substr($ds, 15, 2);
	my $sec  = substr($ds, 18, 2);

	# Converting the month name to the serial number minus 1
	for  ($i = 0; $i < @months; $i++)  {
		last if $months[$i] eq $mon;
	}
	if ($i < @months) {
		$mon = $i;
	} else {
    		$mon = -1;
	}

	# Conversion of the year
	$year -= 1900;

	# Calculating the UnixTime timestamp of a journal entry
	my $logtime = mktime($sec, $min, $hour, $day, $mon, $year);

	print $line_ if ($logtime > ($curtime - $delay));
}
Maybe it will be helpful for you.
 
Old 05-01-2018, 09:27 AM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
What? a perl script with no regexp to extract informations from text files? Congrat for being original
 
  


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
Need to automatically create duplicate copy of log files in real time taximan Linux - Server 2 05-26-2015 10:43 AM
Preserve time stamps of files on a linux based NAS acidrop Linux - Server 2 10-04-2013 05:21 AM
[SOLVED] add time stamps to files VickIsSlick Linux - Newbie 5 12-16-2010 07:53 PM
[SOLVED] Files sizes and checksums changed, but not time stamps? spockdude Linux - Security 2 11-24-2010 03:27 PM
Samba time-stamps files incorectly k41184 Linux - Software 1 10-02-2005 08:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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