I've written a simple ksh script to list the last login for all the users on my systems. The problem is that it uses the last command and if the user hasn't logged in since the wtmp file was created I only get the following from last:
.
wtmp begins Feb 23 11:40
.
My script looks like this
#!/bin/ksh
for i in `lsuser -a ALL`
do
echo `last -1 $i` >> /tmp/lastloginnew.txt
done
I also found the following script here, on this forum, but it was from 2005 so I decided that it wasn't probably being monitored.
#!/bin/ksh
UIDS=`last | cut -f1 -d' ' | cat -n | sort -k 2.1 | uniq -f1 | sort
-n | cut -f2`
for UID in $UIDS
do
last -1 $UID
done
Both of these give me the same thing, just that the first redirects the output to a file that I can e-mail to other team members.
What I'm looking for is some way for the script to print the user name prior to running the last command so that each line will give me the user name the last command is running for. Any help would be greatly appreciated.
-Chas