Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Parse apache log file with three different time formats Post 303038311 by Neo on Friday 30th of August 2019 05:13:53 AM
Old 08-30-2019
It's always best in my view to convert date and time strings to unixtime and do all calculations in unixtime and then convert the results back to a time string based on locale (local time information, timezone information, etc.).

It's kinda "nutty" in my view to try to manipulate / process time using formatted strings which are only a string representation of a "time" in the local time format.

That is why we store "time" in databases as unix timestamps. We do not, generally speaking, store "time" as a formatted time string.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

2. Shell Programming and Scripting

Setting of two time formats in one machine

Hi, Is it possible to set the two time formats in a single machine. My machine time is in EST and the logs are in PST. What would be the issue, and how to make change of this.? (5 Replies)
Discussion started by: gsiva
5 Replies

3. Shell Programming and Scripting

sed command to parse Apache config file

Hi there, am trying to parse an Apache 'server' config file. A snippet of the config file is shown below: ..... ProxyPassReverse /foo http://foo.example.com/bar ..... ..... RewriteRule ^/(.*) http://www.example.com/$1 RewriteRule /redirect https://www.example1.com/$1 ........ (7 Replies)
Discussion started by: jy2k7ca
7 Replies

4. Shell Programming and Scripting

Extracting data from a log file with date formats

Hello, I have a log file for the year, which contains lines starting with the data in the format of YYYY-MM-DD. I need to get all the lines that contain the DD being 04, how would I do this? I tried using grep "*-*04" but it didn't work. Any quick one liners I should know about? Thank you. (2 Replies)
Discussion started by: cpickering
2 Replies

5. Shell Programming and Scripting

Check/Parse log file's lines using time difference/timestamp

I was looking at this script which outputs the two lines which differs less than one sec. #!/usr/bin/perl -w use strict; use warnings; use Time::Local; use constant SEC_MILIC => 1000; my $file='infile'; ## Open for reading argument file. open my $fh, "<", $file or die "Cannot... (1 Reply)
Discussion started by: cele_82
1 Replies

6. Shell Programming and Scripting

Using awk to parse a file with mixed formats in columns

Greetings I have a file formatted like this: rhino grey weight=1003;height=231;class=heaviest;histology=9,0,0,8 bird white weight=23;height=88;class=light;histology=7,5,1,0,0 turtle green weight=40;height=9;class=light;histology=6,0,2,0... (2 Replies)
Discussion started by: Twinklefingers
2 Replies

7. Shell Programming and Scripting

Parse A Log File

Hello All, Below is the excerpt from my Informatica log file which has 4 blocks of lines (starting with WRITER_1_*_1). Like these my log file will have multiple blocks of same pattern. WRITER_1_*_1> WRT_8161 TARGET BASED COMMIT POINT Thu May 08 09:33:21 2014... (13 Replies)
Discussion started by: Ariean
13 Replies

8. Shell Programming and Scripting

Shell Script | Parse log file after a given date and time stamp

I am developing one script which will take log file name, output file name, date, hour and minute as an argument and based on these inputs, the script will scan and capture all the error(s) that have been triggered from a given time. Example: script should capture all the error after 13:50 on Jan... (2 Replies)
Discussion started by: ROMA3
2 Replies

9. Shell Programming and Scripting

Comparing different time formats

I am trying to do a comparison of files based on their last modified date. I am pulling the first file from a webapp folder using curl. curl --silent -I http://localhost:8023/conf/log4j2.xml | grep Last Last-Modified: Tue, 22 Mar 2016 22:02:18 GMT The second file is on local disk. stat... (2 Replies)
Discussion started by: Junaid Subhani
2 Replies

10. Shell Programming and Scripting

Perl to parse a variety of formats

The below perl script parses a variety of formats. If I use the numeric text file as input the script works correctly. However using the alpha text file as input there is a black output file. The portion in bold splits the field to parse f or NC_000023.10:g.153297761C>A into a variable $common but... (3 Replies)
Discussion started by: cmccabe
3 Replies
ntp_time(n)						      Network Time Facilities						       ntp_time(n)

__________________________________________________________________________________________________________________________________________________

NAME
ntp_time - Tcl Time Service Client SYNOPSIS
package require Tcl 8.0 package require time ?1.2.1? ::time::gettime ?options? timeserver ?port? ::time::getsntp ?options? timeserver ?port? ::time::configure ?options? ::time::cget name ::time::unixtime token ::time::status token ::time::error token ::time::reset token ?reason? ::time::wait token ::time::cleanup token _________________________________________________________________ DESCRIPTION
This package implements a client for the RFC 868 TIME protocol (http://www.rfc-editor.org/rfc/rfc868.txt) and also a minimal client for the RFC 2030 Simple Network Time Protocol (http://www.rfc-editor.org/rfc/rfc2030.txt). RFC 868 returns the time in seconds since 1 January 1900 to either tcp or udp clients. RFC 2030 also gives this time but also provides a fractional part which is not used in this client. COMMANDS
::time::gettime ?options? timeserver ?port? Get the time from timeserver. You may specify any of the options listed for the configure command here. This command returns a token which must then be used with the remaining commands in this package. Once you have finished, you should use cleanup to release all resources. The default port is 37. ::time::getsntp ?options? timeserver ?port? Get the time from an SNTP server. This accepts exactly the same arguments as ::time::gettime except that the default port is 123. The result is a token as per ::time::gettime and should be handled in the same way. Note that it is unlikely that any SNTP server will reply using tcp so you will require the tcludp or the ceptcl package. If a suit- able package can be loaded then the udp protocol will be used by default. ::time::configure ?options? Called with no arguments this command returns all the current configuration options and values. Otherwise it should be called with pairs of option name and value. -protocol number Set the default network protocol. This defaults to udp if the tcludp package is available. Otherwise it will use tcp. -port number Set the default port to use. RFC 868 uses port 37, RFC 2030 uses port 123. -timeout number Set the default timeout value in milliseconds. The default is 10 seconds. -command number Set a command procedure to be run when a reply is received. The procedure is called with the time token appended to the argu- ment list. -loglevel number Set the logging level. The default is 'warning'. ::time::cget name Get the current value for the named configuration option. ::time::unixtime token Format the returned time for the unix epoch. RFC 868 time defines time 0 as 1 Jan 1900, while unix time defines time 0 as 1 Jan 1970. This command converts the reply to unix time. ::time::status token Returns the status flag. For a successfully completed query this will be ok. May be error or timeout or eof. See also ::time::error ::time::error token Returns the error message provided for requests whose status is error. If there is no error message then an empty string is returned. ::time::reset token ?reason? Reset or cancel the query optionally specfying the reason to record for the error command. ::time::wait token Wait for a query to complete and return the status upon completion. ::time::cleanup token Remove all state variables associated with the request. % set tok [::time::gettime ntp2a.mcc.ac.uk] % set t [::time::unixtime $tok] % ::time::cleanup $tok % set tok [::time::getsntp pool.ntp.org] % set t [::time::unixtime $tok] % ::time::cleanup $tok proc on_time {token} { if {[time::status $token] eq "ok"} { puts [clock format [time::unixtime $token]] } else { puts [time::error $token] } time::cleanup $token } time::getsntp -command on_time pool.ntp.org AUTHORS
Pat Thoyts BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category ntp of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. SEE ALSO
ntp KEYWORDS
NTP, SNTP, rfc 2030, rfc 868, time COPYRIGHT
Copyright (c) 2002, Pat Thoyts <patthoyts@users.sourceforge.net> ntp 1.2.1 ntp_time(n)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy