10-07-2009
Date comparison with 'string date having slashes and time zone' in Bash only
1. The problem statement, all variables and given/known data:
I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format [31/Mar/2002:19:30:41 +0200].
I have developed a log analysis command line utility that displays different statistics from the log (like the IP with most connection attempts, the most common result codes etc.). In fact to view every stat the user will have to give a specific switch to my utility.
Now comes the problem; with every stat the user can ask to display the results for either 1. previous n hours. or 2. previous n days. I am unable to use the date from the file with format [31/Mar/2002:19:30:41 +0200] and make a comparison with the timestamp of previous n hours or previous n days.
Constraint: I have to attempt this is only in bash.
2. School (University) and Course Number:
Blekinge Institute of Technology
MS Computer Science
10 More Discussions You Might Find Interesting
1. Tips and Tutorials
The GNU date command in full of goodies but not when it comes to calculate a date or time difference. Here is what I came up with after looking to more than one solution.
Code should be self explaining.
#!/bin/bash
date2stamp () {
date --utc --date "$1" +%s
}
stamp2date (){
... (0 Replies)
Discussion started by: ripat
0 Replies
2. Shell Programming and Scripting
I have a CSV (comma separated vaule) file whose entries resemble
Area,\\ntsvsp02\vmcs\download\files\Areas.dat,1,20090303,0,Import Complete,2009-03-02 04:23:00
Product,\\ntsvsp02\vmcs\download\files\items.dat,1,20090303,0,Import Complete,2009-03-02 04:23:00... (3 Replies)
Discussion started by: zainravi
3 Replies
3. Shell Programming and Scripting
Hi
I have this simple script:
#!/bin/bash
date1=2009:07:15:12:36
date2=2009:07:15:12:16
echo $date1
echo $date2
datediff=
#datediff=date1-date2
echo datediff is$datediff
How do i return the difference in seconds? (6 Replies)
Discussion started by: carp.dk
6 Replies
4. Shell Programming and Scripting
Hi,
We have a server in US and hence while the command "date" is given it gives the output in EDT. If I want the date output in MET, how can I get it. Please let me know how I could do it in the script which is ksh. Thanks. (1 Reply)
Discussion started by: jmathew99
1 Replies
5. Shell Programming and Scripting
Hi,
I'm having two fields in the file
F1|F2
20111220|102000
F1 ->YYYYMMDD
F2 ->HHMMSS
Now, I need to compare this with current date & time and need to return the difference value in hours. Already, I checked with datecalc from the forum. So, need hints from Shell Gurus.
Thanks (10 Replies)
Discussion started by: buzzusa
10 Replies
6. Shell Programming and Scripting
Hi
Summary:
- Script will take 2 arguments
- Argument 1: Date/Time value in a particular format
- Argument 2: TimeZone value
Examples:
Argument 1:
a. "May 11, 2012 08:00:00 AM"
b. "Dec 21, 2012 12:21:12 PM"
c. "Oct 2, 2012 05:00:00 PM"
Argument 2:
a. MT or MST or MDT
b. ET
c.... (4 Replies)
Discussion started by: anuragpgtgerman
4 Replies
7. UNIX for Dummies Questions & Answers
I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk.
I tried
This is how each line of the file looks like, different date and time in this format
Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th
... (2 Replies)
Discussion started by: bkkid
2 Replies
8. Solaris
I have a cluster of two Solaris server (veritas cluster). one working and the other is standby
I am going to change the date on them , and am looking for a secure solution as it is giving an important service.
my opinion is that the active one doesn't need to be restarted (if I don't change the... (1 Reply)
Discussion started by: barry1946
1 Replies
9. Shell Programming and Scripting
I'm looking for a way to have the "date" command output the date in a specific format.
I'm not familiar with the different ways to use the date command at all. i read up on it, but i dont get how to manipulate it.
i know that i can get the date format to give me a format like:
2012-10-13... (6 Replies)
Discussion started by: SkySmart
6 Replies
10. Shell Programming and Scripting
I am trying to convert local time to time in Ireland. Instead it is going the opposite direction (taking the local time as it if were in Ireland and displaying that the time would be here).
$ echo "$TZ"; date; date --date='TZ="Europe/Dublin" '"$(date)"
America/Phoenix
Mon, Apr 13, 2015... (7 Replies)
Discussion started by: Michael Stora
7 Replies
LEARN ABOUT DEBIAN
common2dlf
COMMON2DLF.IN(1) LogReport's Lire Documentation COMMON2DLF.IN(1)
NAME
common2dlf - convert Common Log Format web server log files to www DLF
SYNOPSIS
common2dlf file
DESCRIPTION
common2dlf converts Common Log Format web server log files to the www DLF. Common Log Format is a standard log format that was originally
implemented in the CERN httpd web server but that now supported nowadays by most web servers. Apache, IIS, Boa and PureFTPD can be
configured to log in that format.
If the file argument is missing, STDIN will get parsed. DLF will be printed on STDOUT.
COMMON LOG FORMAT
The Common Log Format has the following format:
remotehost rfc931 authuser [date] "request" status bytes
where the fields have the following meaning:
remotehost
The host that made the request. Can be an IP or a hostname.
rfc931
The result of an ident lookup on the host. This is usually never used.
authuser
The authenticated username.
date
The timestamp of the request.
request
The first line of the request. Usually in the format "method request-uri http-version".
See also RFC 2616, section 5.1.
status
The result status of the request. i.e. 200, 301, 404, 500.
bytes
The size of the request sent to the client.
Log example:
127.0.01 - - [11/03/2001 12:12:01 -0400] "GET / HTTP/1.0" 200 513
dsl1.myprovider.com - francis [11/03/2001 12:14:01 -0400] "GET /secret/ HTTP/1.0" 200 1256
EXAMPLES
To process a log as produced in the common logformat:
$ lr_run common2dlf < common.log
common2dlf will be rarely used on its own, but is more likely called by lr_log2report:
$ lr_log2report common < /var/log/httpd/common.log
SEE ALSO
combined(2), modgzip2dlf(1), referer2dlf(1)
AUTHORS
Joost van Baal <joostvb@logreport.org>, Francis J. Lacoste <flacoste@logreport.org> and Egon Willighagen <egonw@logreport.org>, based on an
idea by Edwin Groothuis
VERSION
$Id: common2dlf.in,v 1.15 2006/07/23 13:16:36 vanbaal Exp $
COPYRIGHT
Copyright (C) 2000, 2001 Stichting LogReport Foundation LogReport@LogReport.org
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html.
Lire 2.1.1 2006-07-23 COMMON2DLF.IN(1)