Printout of users in Aix with last log in

amnhtech
amnhtech used Ask the Experts™
on
Hi,
I would like to know how to get a printout of all the user accounts in aix with their last log in date.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007
Commented:
Hi,

All users names are in /etc/passwd

so, the lines below (put them in sh script) will show login history for all of your users and keep the output in a file called users.lastlogin

for user in `awk -F":" '{print $1}' /etc/passwd`
do
echo $user >> users.lastlogin
echo >> users.lastlogin
last $user | grep -v "wtmp begin" | head -5  >> users.lastlogin
echo >> users.lastlogin
done

Notes:

1- If you want to provide the users names yourself instead of using awk, replace `awk -F":" '{print $1}' /etc/passwd` with your list e.g. user1 user2 user3
2- head -5 will show five lines (each line is a login info) from the last $user output. If interested in different number of lines, then change -5 to your own e.g. -1
3- The users.lastlogin will show user name followed by 5 lines of his/her last login. These could be blank  for those users that never logged in or system users, or did not login after rotating wtmp file. wtmp file is the one that keeps the login history on the server.
4- you may use vi to create the script (call it last_users_login).
5- to run the script

chmod u+x  last_users_login
./ last_users_login

Top Expert 2007

Commented:
Hi,

I am new to such recommendation:  Accept: omarfarid {http:#19193009}

Can you please elaborate ?

Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial