Sponsored Content
Top Forums Shell Programming and Scripting Suggestions for Inserting Missing Timestamps Post 302395066 by durden_tyler on Sunday 14th of February 2010 06:37:41 PM
Old 02-14-2010
Quote:
Originally Posted by st33lz
...
I need to insert each missing second and a zero for the request.

I'm really not sure how to go about doing that. I guess create a loop that would create a time stamp for each second of the 24 hour period (84600 seconds) and then grep the file for that second.
...
Here's a Perl solution that generates such data for today. A slight variation though. To grep a file for every second in the day would not be too efficient.

Instead, this program goes through the file first and populates a hash that has the timestamp as the key and number of requests as its value.

Thereafter, it generates the loop for all seconds for today and either prints the number of requests, if it exists in the hash, or 0 if not.

Code:
$ 
$ # display the contents of the log file
$ # I've added boundary values to ensure the loop works as expected
$ cat apache.log
00:00:00 997
00:00:01 998
00:00:02 999
00:00:03 1000
03:04:01 3
03:04:03 2
03:04:04 1
03:04:05 1
03:04:07 2
23:59:56 997
23:59:57 998
23:59:58 999
23:59:59 9999
$ 
$ # show the Perl program
$ cat -n apache.pl
     1  #!/usr/bin/perl -w
     2  use Date::Calc qw(Today Add_Delta_DHMS);
     3
     4  # first, go through the log file and fill up the hash %requests
     5  $logfile="apache.log";
     6  open (LOG, $logfile) or die "Can't open $logfile: $!";
     7  while (<LOG>) {
     8    chomp(@x = split);
     9    $requests{$x[0]} = $x[1];
    10  }
    11  close (LOG) or die "Can't close $logfile: $!";
    12
    13  # now generate the loop for today, and print the 
    14  # key value if present in the hash, or 0 otherwise
    15  ($year,$month,$day) = Today;
    16  $hour = $min = $sec = 0;
    17  foreach (1..24*60*60) {
    18    $hms = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
    19    $reqnum = defined ($requests{$hms}) ? $requests{$hms} : 0;
    20    printf("%02d/%02d/%04d %02d:%02d:%02d %s\n",$month,$day,$year,$hour,$min,$sec,$reqnum);
    21    ($year,$month,$day, $hour,$min,$sec) = Add_Delta_DHMS($year,$month,$day,$hour,$min,$sec,0,0,0,1);
    22  }
    23
$
$ # now run the program
$ # I've snipped most of the output to save storage space, and
$ # to keep forum members from thinking I've lost my mind. ;)
$ # You may want to redirect the output to a file.
$
$ perl apache.pl
02/14/2010 00:00:00 997
02/14/2010 00:00:01 998
02/14/2010 00:00:02 999
02/14/2010 00:00:03 1000
02/14/2010 00:00:04 0
02/14/2010 00:00:05 0
02/14/2010 00:00:06 0
...
...
02/14/2010 03:04:00 0
02/14/2010 03:04:01 3
02/14/2010 03:04:02 0
02/14/2010 03:04:03 2
02/14/2010 03:04:04 1
02/14/2010 03:04:05 1
02/14/2010 03:04:06 0
02/14/2010 03:04:07 2
02/14/2010 03:04:08 0
...
...
02/14/2010 23:59:54 0
02/14/2010 23:59:55 0
02/14/2010 23:59:56 997
02/14/2010 23:59:57 998
02/14/2010 23:59:58 999
02/14/2010 23:59:59 9999
$ 
$

HTH,
tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix timestamps

Can someone help me with a Unix or perl script to convert the unix timestamps to human readable format? Any help will be highly appreciated... (3 Replies)
Discussion started by: hamsasal
3 Replies

2. Solaris

Difference between two timestamps

I'm writting a script to find the difference between two timestamp. One field i get on delivery time of the file like 07:17 AM and other is my SLA time 06:30 AM I need to find the difference between these two time (time exceeded to meet SLA). Need some suggestions. (8 Replies)
Discussion started by: raman1605
8 Replies

3. Shell Programming and Scripting

timestamps

Hello! I have the following problem. I read a file using perl, each line of this file has the fllowing format. 14/4/2008 8:42:03 πμ|10800|306973223399|4917622951117|1||1259|1|126|492|433||19774859454$ Th first field is the timestamp and the second field is the offset in seconds. How can... (1 Reply)
Discussion started by: chriss_58
1 Replies

4. Shell Programming and Scripting

Compare Timestamps

Hi! Long time reader first time registered user and poster. I've picked up some times and tricks and I'm at a dead end... I've parsed a log file for duplicates and printed only the two fields I need (duplicate entry and time stamp). My question is, with this output, how would I script... (2 Replies)
Discussion started by: rexpokinghorn
2 Replies

5. Shell Programming and Scripting

Help with touch and timestamps

Hello fellow Unix geeks, I have been given a very urgent assignment in my office on writing a particular Shell script but I'm very much new to it.I would appreciate any help from you on solving this problem--which might seem very trivial to you. The Unix flavour is a Sun Solaris one..(not... (6 Replies)
Discussion started by: Digjoy83
6 Replies

6. Shell Programming and Scripting

Comparing two timestamps

Hi all!!, I'm using Ksh and working on Linux. I want to compare two timestamps, timestamp1 and timestamp2. Until, timestamp1 is lesser than timestamp2, i want to do something, lets say print something. The code i have written is: a=`date +%H:%M:%S` b=`date +%H:%M:%S -d" 1... (1 Reply)
Discussion started by: Jayaraman
1 Replies

7. SuSE

How to resolve missing missing dependencies with opensuse 11.3 and 12.3?

Hello, This is a programming question as well as a suse question, so let me know if you think I should post this in programming. I have an application that I compiled under opensuse 12.2 using g77-3.3/g++3.3. The program compiles and runs just fine. I gave the application to a colleague who... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

8. Red Hat

Yum - resolving missing dependencies that are not missing

I am trying to install VirtualBox on RHEL 5 but I need the 32 bit version for 32 bit Windows. When I run yum I get the following: sudo yum localinstall /auto/spvtg-it/spvss-migration/Software/VirtualBox-4.3-4.3.2_90405_el6-1.i686.rpm Loaded plugins: fastestmirror Setting up Local Package... (13 Replies)
Discussion started by: gw1500se
13 Replies

9. Shell Programming and Scripting

Write with a look for timestamps

hello i'm using SOX to generate a spectrogram from a wave file with the command : #sox file.wav -n spectrogram is there a way to create a spectrogram using the same command but reading file timestamps instead of the namefile.wav , since name is changing every 4 hours? (it's saved with... (2 Replies)
Discussion started by: Board27
2 Replies

10. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies
uudemon(4)						     Kernel Interfaces Manual							uudemon(4)

NAME
uudemon.admin, uudemon.cleanu, uudemon.hour, uudemon.poll - Administrative shell scripts for polling remote systems, cleaning up spool directories, reporting status to the system administrator, and routine invocations of the uuxqt and uusched daemons SYNOPSIS
These shell scripts reside in the following directory: /usr/lib/uucp DESCRIPTION
All the scripts can be run from the command line or can be run automatically by the cron daemon. To automatically run the scripts, remove the comment character (#) from the beginning of the relevant line in the /var/spool/cron/crontabs/uucp file. This script reports status to the system administrator. It issues the uustat command to find out the status of uucp jobs. It mails the results to the uucp login ID. The script may be modified to send mail to any login ID such as the uucp administrative login ID (uucpa) or root. This script cleans up the /var/spool/uucp and /var/spool/uucppublic directories by running the uucleanup command. The uucleanup com- mand is run with the following parameters: -C7, -D7, X2, -o2, -W1. This script runs the uusched and uuxqt daemons in the background. This script polls the systems listed in the /usr/lib/uucp/Poll file. The uudemon.poll script should be scheduled before the uudemon.hour script. This allows uudemon.poll to create any command files before cron runs the uudemon.hour script. FILES
Contains the uudemon.admin, uudemon.cleanu, uudemon.hour and uudemon.poll files. Contains the uucp file. RELATED INFORMATION
Commands: cron(8), uucleanup(8), uusched(8), uuxqt(1) Files: /usr/lib/uucp delim off uudemon(4)
All times are GMT -4. The time now is 08:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy