• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1067
  • Last Modified:

Aix unix last login need assistance with writing script ksh

I need help writing a script to generate list of last login of all users in a server.
user's information is in /etc/passwd file and the command to list the last login of a user is "last username -n 1".
How can i put those two steps together in a script to get the output of last login of all users?
0
assistunix
Asked:
assistunix
  • 2
  • 2
2 Solutions
 
woolmilkporcCommented:
Did you trY "last" without sspecifying a username?

wmp
0
 
arober11Commented:
Or if you want details for all users, in /etc/passwd file order, and not just those who've logged in try:

finger -sm root | egrep '^Login';(for user in `cat /etc/passwd | cut -f1,1 -d:  `; do finger -sm $user 2>/dev/null; done) | egrep -v '^Login'

Open in new window

0
 
woolmilkporcCommented:
If it has to be a script, so that you can use the "-n 1" flag and also get rid of some garbage:

awk -F: '{print $1}' /etc/passwd | while read user
 do
   last -n 1 $user 2>/dev/null | egrep -v "wtmp|^$"
 done
0
 
arober11Commented:
If you decide to use last opposed to finger then you'll probably want to tweak the syntax slightly; convert the "-n 1" to "-1" to permit the script to also run on Unix (MacOS/Darwin, NetBSD, OpenBSD, FreeBSD, Solaris, AIX...) e.g.

 last -1 $user 2>/dev/null | egrep -v "wtmp|^$"

Open in new window

0
 
assistunixAuthor Commented:
Thank you both.
arober11: your finger command syntax doesn't work right, give's an odd output. your last command only provides the listing of the user that i am logged in as, instead of all the users.

wmp: your command works like magic.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now