How to create script to read time stamps of latest log files
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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'?
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));
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.