"last" command returning duplicates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • grinder332518
    New Member
    • Jun 2009
    • 28

    "last" command returning duplicates

    Hi

    I am running a “last” command and saving the output to a file, which I am going to
    ftp to my PC for loading into a DB table.

    last > last.txt

    I am finding that I am getting lots of duplicate entries for most logins in last.txt.

    Eg

    userabc pts/3 12.42.35.120 Mon Jun 14 09:17 - 09:19 (03:00)
    userabc pts/3 12.42.35.120 Mon Jun 14 09:14 - 09:16 (02:00)
    userabc pts/3 12.42.35.120 Mon Jun 14 09:12 - 09:13 (01:00)
    userdef pts/2 12.42.35.126 Mon Jun 14 10:27 - 09:28 (01:00)
    userdef pts/2 12.42.35.126 Mon Jun 14 10:24 - 09:26 (02:00)


    Is there a way to only retrieve the last login for each user ?

    Thanks
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    Instead of 'last' try 'lastlog'.

    It should display the username and last login time.
    Something like this:

    Code:
    Username         Port     From             Latest
    root             pts/5    172.18.28.86     Fri Dec 17 14:53:18 +0530 2010
    bin                                        **Never logged in**
    daemon                                     **Never logged in**
    adm                                        **Never logged in**
    lp                                         **Never logged in**
    sync                                       **Never logged in**
    shutdown                                   **Never logged in**
    halt                                       **Never logged in**
    If you are not happy with "Never logged in" message, you can use following command:

    lastlog | grep -v 'Never'

    --Ash

    Comment

    • grinder332518
      New Member
      • Jun 2009
      • 28

      #3
      Hi Ashitpro
      My version of unix does not recognise your "lastlog" command.
      Thanks anyway.

      PS The command :
      awk '$1==u || /^$/ {next} {print; u=$1}'
      removes duplicates for me !

      Comment

      Working...