GMT to PST


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers GMT to PST
# 1  
Old 04-04-2011
GMT to PST

Code:
99.60.97.205    -       -       [26/Mar/2011:06:00:00   +0000]  GET /2009-03-29/world/impact.row.atlantic_1_rower-paul-ridley-cancer-research?_s=PM:WORLD HTTP/1.1      200     9386    www.abc.com     Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.107 Safari/534.13        TCP_MISS        Apache=-        -       1068000 -       -       -       deflate=-       rmt=-
72.234.67.132   -       -       [26/Mar/2011:09:00:00   +0000]  GET /ad-abc.php?f=medium_rectangle HTTP/1.1     200     869     www.abc.com     Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.16) Gecko/20101130 Firefox/3.5.16       TCP_HIT Apache=-        -       1000    -       -       -       deflate=-       rmt=-
68.12.178.167   -       -       [26/Mar/2011:09:30:00   +0000]  GET /ad-feedback.js.php?e3e999d9b79cf36c165f5b379a0e9f269be82344 HTTP/1.1       200     600     www.abc.com     Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.6; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) TCP_HIT Apache=-        -       1000    -       -       -       deflate=-       rmt=-
128.186.145.53  -       -       [26/Mar/2011:10:00:00   +0000]  GET /ad-feedback.js.php?e3e999d9b79cf36c165f5b379a0e9f269be82344 HTTP/1.1       200     628     www.abc.com     Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; MAAU; .NET4.0C)    TCP_HIT Apache=-        -       2000    -       -       -       deflate=-       rmt=-
174.253.212.250 -       -       [27/Mar/2011:05:00:00   +0000]  GET /css/ap-CN1-G02.css?e3e999d9b79cf36c165f5b379a0e9f269be82344 HTTP/1.1       200     7146    www.abc.com     Mozilla/5.0 (Linux; U; Android 2.2; en-us; ADR6300 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1   TCP_HIT Apache=-        -       5000    -       -       -       deflate=-       rmt=-
99.60.97.205    -       -       [27/Mar/2011:04:00:00   +0000]  GET /css/ap-CN2-G02.css?e3e999d9b79cf36c165f5b379a0e9f269be82344 HTTP/1.1       200     7125    www.abc.com     Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.107 Safari/534.13        TCP_HIT Apache=-        -       2000    -       -       -       deflate=-       rmt=-
72.234.67.132   -       -       [27/Mar/2011:05:00:00   +0000]  GET /css/ap-CN-G02-FN-01.css?9a7045bca32825fa0b5406740c4161bccd455ef2 HTTP/1.1  200     7049    www.abc.com     Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.16) Gecko/20101130 Firefox/3.5.16       TCP_HIT Apache=-        -       0       -       -       -       deflate=-       rmt=-
76.91.142.36    -       -       [27/Mar/2011:06:00:00   +0000]  GET /css/ap-CN-G02-FN-01.css?e3e999d9b79cf36c165f5b379a0e9f269be82344 HTTP/1.1  200     41888   www.abc.com     Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)      TCP_HIT Apache=-        -       27000   -       -       -       deflate=-       rmt=-
68.12.178.167   -       -       [27/Mar/2011:06:30:10   +0000]  GET /favicon.ico HTTP/1.1       200     5873    www.abc.com     Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.6; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) TCP_HIT Apache=-        -       1000    -       -       -       deflate=-       rmt=-
128.186.145.53  -       -       [27/Mar/2011:09:00:00   +0000]  GET /favicon.ico HTTP/1.1       200     5904    www.abc.com     Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; MAAU; .NET4.0C)    TCP_HIT Apache=-        -       1000    -       -       -       deflate=-       rmt=-

Please tell me how to replace the 4th column to PST time. Now it is in GMT time.
# 2  
Old 04-04-2011
What operating system are you on?
# 3  
Old 04-04-2011
you can use date -s if your on linux
# 4  
Old 04-04-2011
this looks like apache webserver log, you need define GMT time in apache conf , not update it later.
# 5  
Old 04-05-2011
awk/nawk/gawk is unsuitable for this task. You need to use something like Perl or Python

For the purposes of demonstration I have trimmed the Apache log file (infile) down to
Code:
99.60.97.205    -       -       [26/Mar/2011:06:00:00 +0000]  GET
72.234.67.132   -       -       [26/Mar/2011:09:00:00 +0000]  GET
68.12.178.167   -       -       [26/Mar/2011:09:30:00 +0000]  GET
128.186.145.53  -       -       [26/Mar/2011:10:00:00 +0000]  GET
174.253.212.250 -       -       [27/Mar/2011:05:00:00 +0000]  GET
99.60.97.205    -       -       [27/Mar/2011:04:00:00 +0000]  GET
72.234.67.132   -       -       [27/Mar/2011:05:00:00 +0000]  GET
76.91.142.36    -       -       [27/Mar/2011:06:00:00 +0000]  GET
68.12.178.167   -       -       [27/Mar/2011:06:30:10 +0000]  GET
128.186.145.53  -       -       [27/Mar/2011:09:00:00 +0000]  GET

The following Python code with convert the time field to UTC - 0700
Code:
#!/usr/bin/python

from datetime import datetime
from pytz import timezone
import time
import pytz
import re

utc = pytz.utc
pacific = timezone("US/Pacific")

log_re = '(?P<ip>[.\d]+)(\s+)-(\s+)-(\s+)\[(?P<time>.+)\](\s+)GET'
pattern = re.compile(log_re)

for line in open("infile"):
    # print line
    m = pattern.match(line)
    if m is None:
        print "ERROR"
        continue

    res = m.groupdict()

    dt = time.strptime(res["time"][:-6], "%d/%b/%Y:%H:%M:%S")
    utc_dt = datetime(dt[0], dt[1], dt[2], dt[3], dt[4], dt[5], tzinfo=utc)
    tz_dt = utc_dt.astimezone(pacific)

    print res["ip"] + "\t-\t -\t[" + tz_dt.strftime("%d/%b/%Y:%H:%M:%S %z") + "]\tGET"

Here is the output
Code:
99.60.97.205	-	 -	[25/Mar/2011:23:00:00 -0700]	GET
72.234.67.132	-	 -	[26/Mar/2011:02:00:00 -0700]	GET
68.12.178.167	-	 -	[26/Mar/2011:02:30:00 -0700]	GET
128.186.145.53	-	 -	[26/Mar/2011:03:00:00 -0700]	GET
174.253.212.250	-	 -	[26/Mar/2011:22:00:00 -0700]	GET
99.60.97.205	-	 -	[26/Mar/2011:21:00:00 -0700]	GET
72.234.67.132	-	 -	[26/Mar/2011:22:00:00 -0700]	GET
76.91.142.36	-	 -	[26/Mar/2011:23:00:00 -0700]	GET
68.12.178.167	-	 -	[26/Mar/2011:23:30:10 -0700]	GET
128.186.145.53	-	 -	[27/Mar/2011:02:00:00 -0700]	GET

To include the remaining parts of the log file, you need to extend log_re to handle the various patterns and
then add the additional elements to the output print statement. I leave that and better error handling to you.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting timestamp from PST to UTC

I need to convert the given datetime from PST to UTC, i gone through multiple forum examples but everywhere it mentioned about converting the server datetime. So could someone help me on this. I will be getting arguments for my script in the format of yyyymmddhh (eg:2015101004 - it will be pst),... (4 Replies)
Discussion started by: close2jay
4 Replies

2. Windows & DOS: Issues & Discussions

Reading MS Outlook pst file

I found a few products that claim to be able to recover deleted emails. Any recommendations? (1 Reply)
Discussion started by: jgt
1 Replies

3. Solaris

Changing the timezone to GMT+1

Hello everyone, Can you please help me with this problem? I want to change the timezone of my Solaris 10 system. I found on internet that I should do the following steps: 1- Edit the /etc/TIMEZONE file 2- restart the system : init 6 My question is : In the file /etc/TIMEZONE I should... (5 Replies)
Discussion started by: adilyos
5 Replies

4. Shell Programming and Scripting

Calculate time difference between pst and pdt dates in perl

Hi, how to calculate the time difference between PST date and PDT date in perl scripting. date1: Mon Dec 31 16:00:01 PST 2015 date2: Tue Mar 19 06:09:30 PDT 2013 and also difference between PST-PST and PDT-PDT need difference in months or days (months prefereble). (3 Replies)
Discussion started by: praveen265
3 Replies

5. Shell Programming and Scripting

GMT to PST

I have a file which is tab delimited, it contains the GMT date. Please tell me how to convert from GMT to PST time and if the date and time is of 2 days ago from the current date store the lines in a file or else remove the line. 10.1.10.178 - - - 10.1.10.178 - - ... (2 Replies)
Discussion started by: sandy1028
2 Replies

6. Shell Programming and Scripting

Help me about gmt scripts

does somebody know GMT mapping? please reply (2 Replies)
Discussion started by: SANGUINE
2 Replies

7. UNIX for Advanced & Expert Users

changing sys clock (PST to UTC)

Hi I'm trying to change my sys clock from PST to UTC. I've read the man date page it helpfully says :- -u, --utc, --universal print or set Coordinated Universal Time as root I have tried date --universal, date -u, date --utc, I have checked the /etc/sysinfo/clock file the... (5 Replies)
Discussion started by: OFFSIHR
5 Replies
Login or Register to Ask a Question