Find the answer to your Linux question:
Results 1 to 4 of 4
Hi All, How can convert the next lines into seconds: Jun 20 01:06:12 Jul 4 03:57:35 Jul 14 13:35:49 need to parse the messages logs every hour to see how ...
  1. #1
    Just Joined!
    Join Date
    Jul 2011
    Posts
    2

    convert reboot time from messages log into seconds

    Hi All,

    How can convert the next lines into seconds:

    Jun 20 01:06:12
    Jul 4 03:57:35
    Jul 14 13:35:49

    need to parse the messages logs every hour to see how many reboot were done.

    Thanks
    H.

  2. #2
    Linux Guru
    Join Date
    May 2011
    Posts
    1,842
    use the date command and the 'seconds since Epoch' output format, e.g.:
    Code:
    #!/bin/bash
    now=$(date +%s)
    reboot1=$(date +%s -d 'Jun 20 01:06:12')
    diff=$(($now - $reboot1))
    echo "reboot 1 happened $diff seconds ago"

  3. #3
    Just Joined!
    Join Date
    Jul 2011
    Posts
    2

    wow...thanks a lot....more in body

    How can i make the same work in Solaris?

  4. #4
    Linux Guru
    Join Date
    May 2011
    Posts
    1,842
    Can you install the Gnu coreutils package (which contains the date command) for Solaris on this box? If so, get it here.

    Check out this thread, too, for advice on using Perl to do it, too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...