Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    36
    Rep Power
    14

    Unhappy Getting Users' last login timestamp


    Does anyone know how to get the last login timestamp for all the users who have used the system. I use logins -utx but it dosent give the last logins of the users. Can anyone help? Thx in adv.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    36
    Rep Power
    14
    Basically i have a list of users already sorted in a file and i use the logins commands to get all the users that have logged in to the system and uniq the two lists to get the list of users who are not in the result of the logins command. Then i have to get the last login for this list of users and check whether it more than 90 days old...if yes...then i create another list with those users.

    get users's login with last login --> grep users from another file --> compare both and create a new list with users not in the results of the first step --> get the last logins of the users in the new list --> if more than 90 days old then put that user in a new list.

    Any kind of help is greatly appreciated Thnx in adv.
  4. #3
  5. Introspective
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    3,317
    Rep Power
    113
    finger


    christo
    This is me: http://chris.uk.com
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    4
    Rep Power
    0
    Originally Posted by Vinod V
    Does anyone know how to get the last login timestamp for all the users who have used the system. I use logins -utx but it dosent give the last logins of the users. Can anyone help? Thx in adv.
    try running:

    last

    to get a list of all logins in /var/adm/wtmpx (or wherever your installation of unix logs logins).

    to get a history of logins for a given user, run:

    last <user>

    if your host rotates the wtmpx file, you can query a given wtmpx file for a history of logins by running:

    last -f <path to wtmpx file>
  8. #5
  9. Introspective
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    3,317
    Rep Power
    113
    why not just use finger to get the last login for the user...

    eg$ finger chris
    Login: chris Name: chris lacy-hulbert
    Directory: /home/chris Shell: /bin/bash
    Office: 07751 615 397
    On since Wed Apr 21 10:05 (BST) on pts/0 from wormwood.mailbox.net.uk
    No mail.
    No Plan.

    the matching is then a no-brainer in PERL.

    christo
    This is me: http://chris.uk.com
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    36
    Rep Power
    14
    I could do that but i have to compare two diff sets of user lists against each other...eg....File1(static list) and File2(Extracted list)....I have to compare file2 with file1 and extract a new list of users who dont exist in file to file3....then get their last logins and then remove those whose last login is more than 90 days old......does that seem logical? thnx
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    6
    Rep Power
    0
    Also if the user is not logged on, it does not give the last log in time.
  14. #8
  15. Introspective
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    3,317
    Rep Power
    113
    Originally Posted by jetiii
    Also if the user is not logged on, it does not give the last log in time.
    yes it does:

    If never logged in:

    bash-2.05b# finger spiration
    Login: spiration Name: spiration
    Directory: /home/spiration Shell: /bin/bash
    Never logged in.
    No mail.
    No Plan.

    If not currently logged in:

    bash-2.05b# finger spira
    Login: spira Name: spira
    Directory: /home/spira Shell: /bin/bash
    Last login Mon May 5 10:21 2003 (BST) on pts/2 from 10.0.0.15
    No mail.
    No Plan.

    what more could you need?

    christo
    This is me: http://chris.uk.com
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    3
    Rep Power
    0
    I am trying to figure this out as well.....although i dont need it to be as complicated. What i have right now is a file with all the usernames (from /etc/passwd) Now is there a way that i can make the finger commad run through that file and finger each username and send the results to a new file?

    thanks,

    straylight
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    103
    Rep Power
    14
    Originally Posted by Straylight
    Now is there a way that i can make the finger commad run through that file and finger each username and send the results to a new file?
    You can write a scipt that will finger each user and send result to file.
    *note: If you go around fingering users, you might get a call from HR.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    3
    Rep Power
    0
    ha, yeah i am sure HR would get a real kick out of that! Anyway, i know you can write a script....i need some more detail than that though
  22. #12
  23. Perl Jedi
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Location
    New Hampshire
    Posts
    116
    Rep Power
    0
    Originally Posted by Vinod V
    I could do that but i have to compare two diff sets of user lists against each other...eg....File1(static list) and File2(Extracted list)....I have to compare file2 with file1 and extract a new list of users who dont exist in file to file3....then get their last logins and then remove those whose last login is more than 90 days old......does that seem logical? thnx
    This sounds suspiciously like a homework question. You decide, my mind is already made up.

    Regards,

    jlk
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    3
    Rep Power
    0
    My question is not a homework question.....i would just like to know how i can make the finger command finger every username in /etc/passwd. I am sure its not very hard, so if you have USEFUL information please bring it on

    thanks,

    straylight
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    103
    Rep Power
    14
    Code:
    #!/usr/bin/perl
    
    # assuming all names are on a seperate line
    open (FILE, "/file_with_names") || die "$!";
    while (<FILE>)
    {
       chomp;
       push @users, $_;
    }
    close FILE;
    
    foreach $name (@users) 
    {
       `finger $name >> OutputFile`;
        print "------------------" >> OutputFile;  #seperator
    }
    This is untested perl, but should work.
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,198
    Rep Power
    17
    fantastic, i wonder how many people insist to use the
    wrong tool 4 the wrong job. really fantastic.
    btw faulkner try:
    Code:
         s/\<\(sep\).\(rate\)\>/\1a\2/g
    Straylight: the job is a 3-lines shell-script like:

    Code:
    #!/bin/sh
    (
       for name in `sed 's/:.*//' /etc/passwd`
       do finger $name
       done
    ) >output
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo