Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
5 replies Latest Post - ‏2011-10-13T23:03:03Z by esv
aixadmin235
aixadmin235
1 Post
ACCEPTED ANSWER

Pinned topic List all users last login detail

‏2011-10-09T18:08:42Z |
I tried pulling out the data of the last logged on details of the users(eventually i need to pull out the data for all the users).I used the command last -1 <user name > . But i was able to pull the correct data for the users that logged in today(current date) .i checked wtmp file but it also contains the data for the users who logged in today(current day). I do not have sudo right .Can anyone help me extracting the last logindate/time for users in the syste .
Updated on 2011-10-13T23:03:03Z at 2011-10-13T23:03:03Z by esv
  • esv
    esv
    118 Posts
    ACCEPTED ANSWER

    Re: List all users last login detail

    ‏2011-10-10T20:43:41Z  in response to aixadmin235
    > aixadmin235 wrote:
    > I tried pulling out the data of the last logged on details of the users(eventually i need to pull out the data for all the users).I used the command last -1 <user name > . But i was able to pull the correct data for the users that logged in today(current date) .i checked wtmp file but it also contains the data for the users who logged in today(current day). I do not have sudo right .Can anyone help me extracting the last logindate/time for users in the syste .
    for user in $( awk -F: '{ print $1}' /etc/passwd)
    do
    lastlog=$(sudo lsuser -a time_last_login $user | awk -F'=' '{print $NF}')
    echo "The last login by $user was on \c"; perl -le "print scalar localtime($lastlog);"
    done
    best regards,
    enrique sanchez.
    • esv
      esv
      118 Posts
      ACCEPTED ANSWER

      Re: List all users last login detail

      ‏2011-10-10T20:44:54Z  in response to esv
      ooops, you don't have sudo.....mmm interesting.
  • Kosala
    Kosala
    141 Posts
    ACCEPTED ANSWER

    Re: List all users last login detail

    ‏2011-10-13T04:00:34Z  in response to aixadmin235
    If you don't have access to /etc/security/lastlog it's likely that you can't find this. This is where it's stored.

    Cheers,
    Ko
    • ColombianJoker
      ColombianJoker
      68 Posts
      ACCEPTED ANSWER

      Re: List all users last login detail

      ‏2011-10-13T22:46:25Z  in response to Kosala
       for u in $(lsuser -a ALL)
      do
      LAST=$(lsuser -a time_last_login $u |awk '/last_login/{print substr($2,17)}')
      && ( printf "$u "; perl -le "print scalar(localtime($LAST))" )
      done
      • esv
        esv
        118 Posts
        ACCEPTED ANSWER

        Re: List all users last login detail

        ‏2011-10-13T23:03:03Z  in response to ColombianJoker
        > ColombianJoker wrote:
        >
         > for u in $(lsuser -a ALL)
        > do
        > LAST=$(lsuser -a time_last_login $u |awk '/last_login/{print substr($2,17)}')
        > && ( printf "$u "; perl -le "print scalar(localtime($LAST))" )
        > done
        >
        you need to execute that as root or use sudo to call the "lsuser -a time_last_login XXX" command.

        regards,
        enrique.