Date/Time problem
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Date/Time problem




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Date/Time problem  
Stefanie


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-06-04 07:54 AM

Hi all,

I am writing a Korn Shell script in which I need to read a line from a
logfile, parse the date from it and check whether that date is older
than five minutes.

The date has this format: "Oct  6 07:51:55 2004"

The problem now is, how can I format this date into unix timestamp
format, so I can compare how old it is?


Thanks,

Stefanie





[ Post a follow-up to this message ]



    Re: Date/Time problem  
Michael Tosch


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-06-04 12:50 PM

In article <b8a63f96.0410060003.56eda17d@posting.google.com>, doofer_spam@yahoo.de (Stefanie
) writes:
> Hi all,
>
> I am writing a Korn Shell script in which I need to read a line from a
> logfile, parse the date from it and check whether that date is older
> than five minutes.
>
> The date has this format: "Oct  6 07:51:55 2004"
>
> The problem now is, how can I format this date into unix timestamp
> format, so I can compare how old it is?
>
>
> Thanks,
>
> Stefanie

perl -le 'print time'

prints the date in Unix time format, i.e. seconds since 1970.
This is easy to calculate.

--
Michael Tosch
IT Specialist
HP Managed Services
Technology Solutions Group
Hewlett-Packard GmbH
Phone: +49 2407 575 313
Mail: michael.tosch:hp.com







[ Post a follow-up to this message ]



    Re: Date/Time problem  
Laurenz Albe


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-06-04 12:50 PM

Stefanie <doofer_spam@yahoo.de> wrote:
> I am writing a Korn Shell script in which I need to read a line from a
> logfile, parse the date from it and check whether that date is older
> than five minutes.
>
> The date has this format: "Oct  6 07:51:55 2004"
>
> The problem now is, how can I format this date into unix timestamp
> format, so I can compare how old it is?

The most elegant solution is to use GNU date.

date -d 'Oct  6 07:51:55 2004' +%s

would do the trick.

Yours,
Laurenz Albe





[ Post a follow-up to this message ]



    Re: Date/Time problem  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-06-04 12:50 PM

2004-10-6, 01:03(-07), Stefanie:
> I am writing a Korn Shell script in which I need to read a line from a
> logfile, parse the date from it and check whether that date is older
> than five minutes.
>
> The date has this format: "Oct  6 07:51:55 2004"
[...]

With recent versions of ksh93, you can do:

$ printf '%(%s)T\n' 'Oct  6 07:51:55 2004'
1097049115

You could use GNU date:

$ date -d 'Oct  6 07:51:55 2004' +%s
1097045515

(notice the 1 hour difference because GNU date assumes the date
is in local time while ksh93 assumes it's in the GMT timezone).

You could also do:

date="Oct  6 07:51:55 2004"
set -f
IFS=" :"
set -- $date
 months=JanFebMarAprMayJunJulAugSepOctNov
Dec
m=${months%%$1*}
typeset -Z2 month="$((${#m} / 3 + 1))" day=$2
touch -t"$6$month$day$3$4.$5" file1
TZ=GMT touch -t"$(TZ=GMT+0:5 date +%Y%m%d%H%M.%S)" file2
if [[ file1 -ot file2 ]]; then
echo "$date is more than 5 minutes old"
fi

--
Stephane





[ Post a follow-up to this message ]



    Re: Date/Time problem  
Ed Morton


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-07-04 07:56 AM



Stefanie wrote:
> Hi all,
>
> I am writing a Korn Shell script in which I need to read a line from a
> logfile, parse the date from it and check whether that date is older
> than five minutes.
>
> The date has this format: "Oct  6 07:51:55 2004"
>
> The problem now is, how can I format this date into unix timestamp
> format, so I can compare how old it is?
>
>
> Thanks,
>
> Stefanie

See question 6 in the FAQ: http://home.comcast.net/~j.p.h/cus-faq.html#G

Regards,

Ed.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:23 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register