Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi
my question is abt scripting.
i want to find the diffrence in two dates.
dates are in /var/log/messagesMar 27 05:48:02 abhargav sshd[1151]:
Apr 2 15:31:17 abhargav sshd[1151]:now i can get the dates in strings using awk
but doesnt solve my purpose.i hav to find the diffrence between these two dates.is there any way that i can convert into milliseconds and then find out the diffrencein simple words,i hav to find the diffrence of two dates.any ideas will be appreciated .
thanx
abhishek
hi
my question is abt scripting.
i want to find the diffrence in two dates.
dates are in /var/log/messagesMar 27 05:48:02 abhargav sshd[1151]:
Apr 2 15:31:17 abhargav sshd[1151]:no
hi
my question is abt scripting.
i want to find the diffrence in two dates.
dates are in /var/log/messagesMar 27 05:48:02 abhargav sshd[1151]:
Apr 2 15:31:17 abhargav sshd[1151]:no

hi
it seems to me that mktime() needs a c library
now i m using bourne shell scripting #!/bin/sh
i hav googled it a lot but cant find out the
exactly how to use mktime(awk scripting using sh) in converting it into time stamp.2) just like ansi c they hav this function of localtime and systime....which returns in milliseconds.....can we do this in bourne shell scripting.
plz give an example
i will be very grateful to u.
thanx
abhishek

Of course awk needs a C library! I'm not talking about the C library mktime() but awk's mktime(). Have you read the awk info page entry for mktime()?
Since you're already using awk you don't need an example, you just need to feed the strings you extract from the log file into awk's mktime() (with a little reformatting first).
Alternatively you could use some combination of sed/grep/shell and the 'date' command, which will take various different formats.
This is a very simple job and there are many tools that can help you do it so you should just read the info/man pages and try them out.
BTW - you won't get milliseconds with either awk's mktime() or using the 'date' command but since you don't need better than seconds resolution anyway, it doesn't really matter does it?

Dear Wolfbone
Thanx a lot for your replies.but as i have written i would be needing an example of mktime or the tools .i hav read the man pages,but i cant implement it.it gives me an syntax error.then at the same time, the assignment that i m doin requires shell scripting without using any c library.
plz if possible give me an example of what u r talking about
thanks a ton
abhishekhi
my question is abt scripting.
i want to find the diffrence in two dates.
dates are in /var/log/messagesMar 27 05:48:02 abhargav sshd[1151]:
Apr 2 15:31:17 abhargav sshd[1151]:no

If you are having trouble using awk or understanding it's info (not man) pages then use the 'date' command and shell arithmetic:
echo $(( $(date -d 'Apr 2 2005 15:31:17' '+%s') - $(date -d 'Mar 27 2005 05:48:02' '+%s') ))
This is in a bash shell and it is trivial to replace the two date strings with variables set to strings extracted from the log file.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |